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
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
| | TITLE:コードプラグイン
#indent
#contents
- 謎な帳尻合わせがあるが、とりあえず削除。
-- 対症療法。そもそも、どっかで必要のために帳尻合わせしてるハズなので要調査。
-##plugin/code/codehighlight.php## の ##function highlight## の前半にて、
#code(diff){{{{
if (file_exists(PLUGIN_DIR.'code/keyword.'.$lang.'.php')) {
……
} else if (file_exists(PLUGIN_DIR.'code/line.'.$lang.'.php')) {
……
} else {
$option['outline'] = false;
$option['comment'] = false;
- // 最後の余分な改行を削除
- if ($src[strlen($src)-2] == ' ')
- $src = substr($src, 0, -2);
- else
- $src= substr($src, 0, -1);
if ($option['number']) {
$num_of_line = substr_count($src, "\n");
if($src[strlen($src)-1]=="\n")
$src=substr($src,0,-1);
$data = array('number' => '');
$data['number'] = _plugin_code_makeNumber($num_of_line-1);
}
……
}}}}
- 行数は自然数で数える方が自然かと。
- 次の改造と合わせ、##_plugin_code_makeNumber## の呼出しが単純で規則的になる。
- ##plugin/code/codehighlight.php## の #function _plugin_code_makeNumber## にて、
#code(diff){{{{
-function _plugin_code_makeNumber($end, $begin=0)
+function _plugin_code_makeNumber($end, $begin=1){
$number='';
$str_len=max(3,strlen(''.$end));
for($i=$begin; $i<=$end; ++$i) {
$number.= sprintf('%'.$str_len.'d',($i))."\n";
}
return $number;
}
}}}}
- 同ファイル、##function highlight## の前半で、平コードの改造の直後にて、
#code(diff){{{{
if (file_exists(PLUGIN_DIR.'code/keyword.'.$lang.'.php')) {
……
} else if (file_exists(PLUGIN_DIR.'code/line.'.$lang.'.php')) {
……
} else {
$option['outline'] = false;
$option['comment'] = false;
if ($option['number']) {
$num_of_line = substr_count($src, "\n");
if($src[strlen($src)-1]=="\n")
$src=substr($src,0,-1);
$data = array('number' => '');
- $data['number'] = _plugin_code_makeNumber($num_of_line-1);
+ $data['number'] = _plugin_code_makeNumber($num_of_line);
}
……
}}}}
- 同ファイル、##function lineToHTML## の最後にて、
#code(diff){{{{
if ($html[strlen($html)-2] == ' ')
$html = substr($html, 0, -2);
else
$html = substr($html, 0, -1);
$html = array( 'src' => $html, 'number' => '', 'outline' => '', 'commentnum' => $commentnum,);
- if($mknumber) $html['number'] = _plugin_code_makeNumber($num_of_line-2); // 最後に改行を削除したため -2
+ if($mknumber) $html['number'] = _plugin_code_makeNumber($num_of_line-1); // 最後に改行を削除したため -1
return $html;
}}}}
- 同ファイル、##function srcToHTML## の最後にて、
#code(diff){{{{
if ($html[strlen($html)-2] == ' ')
$html = substr($html, 0, -2);
else
$html = substr($html, 0, -1);
$html = array( 'src' => $html, 'number' => '', 'outline' => '',
'blocknum' => $blockno, 'commentnum' => $commentno, );
if($mkoutline)
return $this->makeOutline($html,$line-1,$nest,$mknumber,$outline,$blockno,$id_number);
- if($mknumber) $html['number'] = _plugin_code_makeNumber($line-1);
+ if($mknumber) $html['number'] = _plugin_code_makeNumber($line);
return $html;
}}}}
- diff をコードの変更を示す目的(汎用差分)で使用する場合、無変更行を位置のマーカーとして表示できると便利。
- この改造により、##_plugin_code_makeNumber## の3箇所の呼出しから引数の補正が無くなる。
- ##plugin/code/line.diff.php## にて、
#code(diff){{{{
...
$switchHash['\\']= PLUGIN_CODE_IDENTIFIRE_CHAR; // control
$switchHash['@'] = PLUGIN_CODE_IDENTIFIRE_CHAR; // control
+ $switchHash[' '] = PLUGIN_CODE_IDENTIFIRE_CHAR; // nochange
...
- $switchHash['#'] = PLUGIN_CODE_COMMENT; // コメントは # から改行まで
+ $switchHash['#'] = PLUGIN_CODE_COMMENT_CHAR; // コメントは # から改行まで
$code_css = Array(
'changed', //
'added', //
'removed', //
'system', //
+ 'nochange',//
);
$code_keyword = Array(
...
'*' => 4,
'\\' => 4,
'@' => 4,
'---' => 4,
'+++' => 4,
+
+ ' ' => 5,
);
}}}}
- ##plugin/code/codehighlight.php## の ##function lineToHTML## にて、
#code(diff){{{{
function lineToHTML(& $string, & $lang, $id_number, & $option) {
...
while($line !== false) {
...
switch ($switchHash[$line[0]]) {
case PLUGIN_CODE_CHAR_COMMENT:
case PLUGIN_CODE_HEAD_COMMENT:
case PLUGIN_CODE_COMMENT_CHAR:
...
- $line = htmlspecialchars(substr($line,0,-1), ENT_QUOTES);
+ $line = htmlspecialchars($line, ENT_QUOTES);
...
$html .= '<span class="'.PLUGIN_CODE_HEADER.'comment" id="'.PLUGIN_CODE_HEADER.$id_number.'_cmt_'.$commentnum.'">'
- .$line.'</span>'."\n";
+ .$line.'</span>';
...
case PLUGIN_CODE_HEADW_COMMENT:
case PLUGIN_CODE_COMMENT_WORD:
if (strncmp($line, $commentpattern, strlen($commentpattern)) == 0) {
...
- $line = htmlspecialchars(substr($line,0,-1), ENT_QUOTES);
+ $line = htmlspecialchars($line, ENT_QUOTES);
...
if ($option['link'])
$html .= '<span class="'.PLUGIN_CODE_HEADER.'comment" id="'.PLUGIN_CODE_HEADER.$id_number.'_cmt_'.$commentnum.'">'
- .$line.'</span>'."\n";
+ .$line.'</span>';
...
- if($mknumber) $html['number'] = _plugin_code_makeNumber($num_of_line-1); // 最後に空行は削除するため -1
+ if($mknumber) $html['number'] = _plugin_code_makeNumber($num_of_line);
}}}}
次のコードで行番号で、数式中の改行を数え忘れ。
^#code(tex){{{{
^ 関数$
^ y = f(x)
^ $と置く。
^}}}}
- ##plugin/code/codehighlight.php## の ##function srcToHTML## の後半、##case PLUGIN_CODE_FORMULA:## にて、
#code(diff){{{{
case PLUGIN_CODE_FORMULA:
$pos = $str_pos;
$result = substr($string, $str_pos);
$pos1 = strpos($result, $code); // 文字列終了文字検索
if ($pos1 === false) { // 文字列が終わらなかったので全部文字列とする
$str_pos = $str_len-1;
} else {
$str_pos += $pos1 + 1;
}
$result = $code.substr($string, $pos, $str_pos - $pos);
+ $line+=substr_count($result,"\n"); // ライン数カウント
$result = htmlspecialchars($result, ENT_QUOTES);
if ($option['link'])
$result = preg_replace('/(s?https?:\/\/|ftp:\/\/|mailto:)([-_.!~*()a-zA-Z0-9;\/:@?=+$,%#]|&)+/',
'<a href="$0">$0</a>',$result);
$html .= '<span class="'.PLUGIN_CODE_HEADER.'formula">'.$result.'</span>';
if ($str_len == $str_pos) $code = false; else $code = $string[$str_pos++]; // getc
continue 2;
}}}}
- 字下げ拡張をしたため、コードプラグインの PukiWiki モードにも対応させるべし。
- ##plugin/code.inc.php## の先頭にて、
#code(diff){{{{
define('PLUGIN_CODE_NUMBER', ture ); // 行番号
define('PLUGIN_CODE_OUTLINE', false); // アウトライン;
define('PLUGIN_CODE_COMMENT', false); // コメント表示/非表示 // 0.5.0 では非推奨
define('PLUGIN_CODE_MENU', false); // メニューの表示/非表示;
define('PLUGIN_CODE_FILE_ICON', false); // 添付ファイルにダウンロードアイコンを付ける
define('PLUGIN_CODE_LINK', false); // オートリンク
define('PLUGIN_CODE_CACHE', false); // キャッシュを使う
+define('PLUGIN_CODE_INDENT', false); // 字下げ拡張
}}}}
-- 天突きモードがデフォルト。
- 同ファイル、##function plugin_code_convert## にて、
#code(diff){{{{
$option = array(
'number' => false, // 行番号を表示する
'nonumber' => false, // 行番号を表示しない
'outline' => false, // アウトライン モード
'nooutline' => false, // アウトライン 無効
'comment' => false, // コメント開閉する
'nocomment' => false, // コメント開閉しない
'menu' => false, // メニューを表示する
'nomenu' => false, // メニューを表示しない
'icon' => false, // アイコンを表示する
'noicon' => false, // アイコンを表示しない
'link' => false, // オートリンク 有効
'nolink' => false, // オートリンク 無効
+ 'indent' => false, // 字下げ 有効
+ 'noindent' => false, // 字下げ 無効
);
}}}}
- ##plugin/code/codehighlight.php## の ##function lineToHTML## にて、
#code(diff){{{{
function lineToHTML(& $string, & $lang, $id_number, & $option) {
$switchHash = Array();
$capital = false; // 大文字小文字を区別しない
$option['outline'] = false; // outlineを使わない
$mknumber = $option['number'];
+ $indent_switch_reg = '/$^/'; // indentに切り替えるキーワード // PukiWikiの字下げ拡張
+ $noindent_switch_reg = '/$^/'; // noindentに切り替えるキーワード // PukiWikiの字下げ拡張
……
while($line !== false) {
++$num_of_line;
while ($line[strlen($line)-2] == '\\') {
++$num_of_line;
$line .= $this->getline($string);
}
+ $line_head = ($option['indent']) ? ltrim($line) : $line; // PukiWikiの字下げ拡張
+ if ( $option['indent'] && preg_match($noindent_switch_reg, $line_head)) $option['indent'] = false;
+ if (! $option['indent'] && preg_match($indent_switch_reg , $line_head)) $option['indent'] = true;
- switch ($switchHash[$line[0]]) {
+ switch ($switchHash[$line_head[0]]) // PukiWikiの字下げ拡張
+ {
case PLUGIN_CODE_CHAR_COMMENT:
case PLUGIN_CODE_HEAD_COMMENT:
case PLUGIN_CODE_COMMENT_CHAR:
++$commentnum;
- $line = htmlspecialchars(substr($line,0,-1), ENT_QUOTES);
+ $line = htmlspecialchars($line, ENT_QUOTES);
……
case PLUGIN_CODE_HEADW_COMMENT:
case PLUGIN_CODE_COMMENT_WORD:
- if (strncmp($line, $commentpattern, strlen($commentpattern)) == 0) {
+ if (strncmp($line_head, $commentpattern, strlen($commentpattern)) == 0) {
++$commentnum;
- $line = htmlspecialchars(substr($line,0,-1), ENT_QUOTES);
+ $line = htmlspecialchars($line, ENT_QUOTES);
……
case PLUGIN_CODE_IDENTIFIRE_CHAR:
- $index = $code_keyword[$line[0]];
+ $index = $code_keyword[$line_head[0]];
$line = htmlspecialchars($line, ENT_QUOTES);
……
case PLUGIN_CODE_IDENTIFIRE_WORD:
if (strlen($line) < 2 && $line[0] == ' ') break; // 空行判定
- foreach ($code_identifire[$line[0]] as $pattern) {
+ foreach ($code_identifire[$line_head[0]] as $pattern) {
- if (strncmp($line, $pattern, strlen($pattern)) == 0) {
+ if (strncmp($line_head, $pattern, strlen($pattern)) == 0) {
……
}
- $index = $code_keyword[$line[0]];
+ $index = $code_keyword[$line_head[0]];
case PLUGIN_CODE_MULTILINE:
- $index = $code_keyword[$line[0]];
+ $index = $code_keyword[$line_head[0]];
$src = $line;
$line = $this->getline($string);
- while (in_array($line_head[0], $multilineEOL) === false && $line !== false) {
+ while (in_array($line[0], $multilineEOL) === false && $line !== false) {
……
}}}}
-- モード切替スイッチは pukiwiki モード側で実装。
--- 9行目、##$indent_switch_reg## は字下げモードへのスイッチ。
--- 10行目、##$noindent_switch_reg## は天突きモードへのスイッチ。
-- 23行目、##$line_head## は字下げ処理後の行。
--- 以降、書式の判定は全て ##$line_head## を使う。
--- ただし、字下げも出力するため、コードの出力は ##$line## のまま。
-- 24、25行目はモードの切り替えの検出と操作。
-
- ##plugin/code/line.pukiwiki.php## にて、
#code(diff){{{{
<?php
+$indent_switch_reg = '/^#indent$/';
+$noindent_switch_reg = '/^#noindent$/';
/**
$switchHash['#'] = PLUGIN_CODE_SPECIAL_IDENTIFIRE; // # から始まる予約語あり
$switchHash['&'] = PLUGIN_CODE_SPECIAL_IDENTIFIRE; // & から始まる予約語あり
$switchHash['*'] = PLUGIN_CODE_IDENTIFIRE_CHAR; // 見出し
$switchHash[','] = PLUGIN_CODE_IDENTIFIRE_CHAR; // 表
$switchHash['|'] = PLUGIN_CODE_IDENTIFIRE_CHAR; // 表
+$switchHash['^'] = PLUGIN_CODE_IDENTIFIRE_CHAR; // 整形済出力
$switchHash[' '] = PLUGIN_CODE_IDENTIFIRE_WORD; // 整形済出力
$switchHash['-'] = PLUGIN_CODE_MULTILINE; // 箇条書
$switchHash['+'] = PLUGIN_CODE_MULTILINE; // 箇条書
$switchHash[':'] = PLUGIN_CODE_MULTILINE; // 箇条書
$switchHash['<'] = PLUGIN_CODE_MULTILINE; // 引用
$switchHash['>'] = PLUGIN_CODE_MULTILINE; // 引用
……
$code_keyword = Array(
……
'*' => 5, // 見出し
',' => 6, // 表
'|' => 6, // 表
'-' => 7, // 箇条書
'+' => 7, // 箇条書
':' => 7, // 箇条書
+ '^' => 8, // 整形済出力
' ' => 8, // 整形済出力
" \n" => 0, // ハイライト無効
'<' => 9, // 引用
'>' => 9, // 引用
);
?>
}}}}
- pukiwiki モードではなく、新たに nekowiki モードを作るべきか?
- 「##<?php ##」と「## ?>##」にマーカを付けて、丸ごと削除。
-- タグは残しても無害なので、放置。
- ##plugin/code/codehightlight.php## の ##class CodeHighlight## の後半、##function highlightPHP## にて、
#code(diff){{{{
function highlightPHP($src) {
$phptagf = false;
if(! strstr($src,'<?php')) {
$phptagf = true;
- $src='<'.'?php '.$src.' ?'.'>';
+ $src='<?php __dammy__head__ '.$src.' __dammy__tail__ ?>';
}
……
if ($phptagf) {
- $html = preg_replace('/<\?php (.*)?(<font[^>]*>\?><\/font>|\?>)/m','$1',$html);
+ $html = preg_replace('/<\?php __dammy__head__ /','',$html);
+ $html = preg_replace('/( )*__dammy__tail__ \?>/','',$html);
}
……
}}}}
- とりあえず等幅フォントで出力
- 色付けは ##codehightlight.php## を理解してから
- ##plugin/code.inc.php## の前半、##function plugin_code_convert##の前にて、
#code(php){{
function plugin_code_inline()
{
return '<span class="code_inline">'.rtrim(rtrim(join(func_get_args(), ','), ','), "\r").'</span>';
}
}}
- code タグを使わないのは、コードが小さく表示されるのを避けるため。
CSSで無効化ができたら使う予定。
### php
<?php
/**
define('PLUGIN_CODE_LANGUAGE', 'pre'); // 標準言語 全て小文字で指定
define('PLUGIN_CODE_NUMBER', ture ); // 行番号
define('PLUGIN_CODE_OUTLINE', false); // アウトライン;
define('PLUGIN_CODE_COMMENT', false); // コメント表示/非表示 // 0.5.0 では非推奨
define('PLUGIN_CODE_MENU', false); // メニューの表示/非表示;
define('PLUGIN_CODE_FILE_ICON', false); // 添付ファイルにダウンロードアイコンを付ける
define('PLUGIN_CODE_LINK', false); // オートリンク
define('PLUGIN_CODE_CACHE', false); // キャッシュを使う
define('PLUGIN_CODE_INDENT', false); // 字下げ拡張
define('PLUGIN_CODE_READ_URL', false);
define('PLUGIN_CODE_TABLE', true);
define('PLUGIN_CODE_WIDTHOFTAB', ' ');
define('PLUGIN_CODE_IMAGE_FILE', IMAGE_DIR.'code_dot.png');
define('PLUGIN_CODE_OUTLINE_OPEN_FILE', IMAGE_DIR.'code_outline_open.png');
define('PLUGIN_CODE_OUTLINE_CLOSE_FILE', IMAGE_DIR.'code_outline_close.png');
if (! defined('FILE_ICON')) {
define('FILE_ICON',
'<img src="' . IMAGE_DIR . 'file.png" width="20" height="20"' .
' alt="file" style="border-width:0px; vertical-align:middle;" />');
}
define('PLUGIN_CODE_USAGE',
'<p class="error">Plugin code: Usage:<br />#code[(Lang)]{{<br />src<br />}}</p>');
function pluing_code_init()
{
global $javascript; $javascript = true;
}
function plugin_code_action()
{
global $vars;
global $_source_messages;
if (PKWK_SAFE_MODE) die_message('PKWK_SAFE_MODE prohibits this');
$vars['refer'] = $vars['page'];
if (! is_page($vars['page']) || ! check_readable($vars['page'],false,false)) {
return array( 'msg' => $_source_messages['msg_notfound'],
'body' => $_source_messages['err_notfound'] );
}
return array( 'msg' => $_source_messages['msg_title'],
'body' => plugin_code_convert('pukiwiki',
join('',get_source($vars['page']))."\n"));
}
function plugin_code_inline()
{
return '<span class="code_inline">'.rtrim(join(func_get_args(), ','), "\r").'</span>';
}
function plugin_code_convert()
{
if (file_exists(PLUGIN_DIR.'code/codehighlight.php'))
require_once(PLUGIN_DIR.'code/codehighlight.php');
else
die_message('file '.PLUGIN_DIR.'code/codehighlight.php not exist or not readable.');
static $plugin_code_jscript_flag = true;
$title = '';
$lang = null;
$option = array(
'number' => false, // 行番号を表示する
'nonumber' => false, // 行番号を表示しない
'outline' => false, // アウトライン モード
'nooutline' => false, // アウトライン 無効
'comment' => false, // コメント開閉する
'nocomment' => false, // コメント開閉しない
'menu' => false, // メニューを表示する
'nomenu' => false, // メニューを表示しない
'icon' => false, // アイコンを表示する
'noicon' => false, // アイコンを表示しない
'link' => false, // オートリンク 有効
'nolink' => false, // オートリンク 無効
'indent' => false, // 字下げ 有効
'noindent' => false, // 字下げ 無効
);
$num_of_arg = func_num_args();
$args = func_get_args();
if ($num_of_arg < 1) {
return PLUGIN_CODE_USAGE;
}
$arg = $args[$num_of_arg-1];
if (strlen($arg) == 0) {
return PLUGIN_CODE_USAGE;
}
if ($num_of_arg != 1 && ! _plugin_code_check_argment($args[0], $option)) {
$is_setlang = true;
$lang = htmlspecialchars(strtolower($args[0])); // 言語名かオプションの判定
} else
$lang = PLUGIN_CODE_LANGUAGE; // default
$begin = 0;
$end = null;
for ($i = 1;$i < $num_of_arg-1; ++$i) {
if (! _plugin_code_check_argment($args[$i], $option))
_plugin_code_get_region($args[$i], $begin, $end);
}
$multiline = _plugin_code_multiline_argment($arg, $data, $option, $begin, $end);
if (PLUGIN_CODE_CACHE && ! $multiline) {
$html = _plugin_code_read_cache($arg);
if ($html != '' or $html != null)
return $html;
}
if (isset($data['_error']) && $data['_error'] != '') {
return $data['_error'];
}
$lines = $data['data'];
$title = $data['title'];
$highlight = new CodeHighlight;
$lines = $highlight->highlight($lang, $lines, $option);
$lines = '<div class="'.$lang.'">'.$lines.'</div>';
if ($plugin_code_jscript_flag && ($option['outline'] || $option['comment'])) {
$plugin_code_jscript_flag = false;
$title .= '<script type="text/javascript" src="'.SKIN_DIR.'code.js"></script>'."\n";
}
$html = $title.$lines;
if (PLUGIN_CODE_CACHE && ! $multiline) {
_plugin_code_write_cache($arg, $html);
}
return $html;
}
/**
function _plugin_code_write_cache($fname, $html)
{
global $vars;
$page = isset($vars['page']) ? $vars['page'] : '';
if (preg_match('#^(.+)/([^/]+)$#', $fname, $matches)) {
if ($matches[1] == '.' || $matches[1] == '..')
$matches[1] .= '/'; // Restore relative paths
$fname = $matches[2];
$page = get_fullname(strip_bracket($matches[1]), $page); // strip is a compat
$file = encode($page) . '_' . encode($fname);
} else {
$file = encode($page) . '_' . encode($fname);
}
$fp = fopen(CACHE_DIR.'code/'.$file.'.html', 'w') or
die_message('Cannot write cache file ' .
CACHE_DIR.'code/'. $file .'.html'.
'<br />Maybe permission is not writable or filename is too long');
set_file_buffer($fp, 0);
flock($fp, LOCK_EX);
rewind($fp);
fputs($fp, $html);
flock($fp, LOCK_UN);
fclose($fp);
}
/**
function _plugin_code_read_cache($fname)
{
global $vars;
$page = isset($vars['page']) ? $vars['page'] : '';
if (preg_match('#^(.+)/([^/]+)$#', $fname, $matches)) {
if ($matches[1] == '.' || $matches[1] == '..')
$matches[1] .= '/'; // Restore relative paths
$fname = $matches[2];
$page = get_fullname(strip_bracket($matches[1]), $page); // strip is a compat
$file = encode($page) . '_' . encode($fname);
} else {
$file = encode($page) . '_' . encode($fname);
}
/* Read file data */
$fdata = '';
$filelines = file(CACHE_DIR.'code/'.$file.'.html');
foreach ($filelines as $line)
$fdata .= $line;
return $fdata;
}
?>
###
|