8c853d04cd87d10ab22cc18f1619980821771f8a
[atutor.git] / mods / wiki / plugins / markup / footnotes.php
1 <?php
2
3  /*
4
5    this plugin introduces markup for footnotes, use it like:
6
7       ...
8       some very scientific sentence {{this is a footnote explaination}}
9       ...
10
11    this may be useful in some rare cases; usually one should create
12    a WikiLink to explain a more complex task on another page;
13    your decision
14
15 */  
16
17
18
19 $ewiki_plugins["format_source"][] = "ewiki_format_source_footnotes";
20
21
22
23 function ewiki_format_source_footnotes (&$source) {
24
25    $notenum = 0;
26
27    $l = 0;
28    while (
29             ($l = strpos($source, "{{", $l))
30         &&  ($r = strpos($source, "}}", $l))
31          )
32    {
33       $l += 2;
34
35       #-- skip "{{...\n...}}"
36       if (strpos($source, "\n", $l) < $r) {
37          continue;
38       }
39
40       $notenum++;
41
42       #-- extract "footnote"
43       $footnote = substr($source, $l, $r - $l);
44
45       #-- strip "{{footnote}}"
46       $source = substr($source, 0, $l - 2)
47              . "<a href=\"#fn$notenum\">·$notenum</a>"
48              . substr($source, $r + 2);
49
50       #-- add "footnote" to the end of the wiki page source
51       if ($notenum==1) {
52          $source .= "\n----";
53       }
54       $source .= "\n" .
55                  "<a name=\"fn$notenum\">·$notenum</a> ". $footnote . "\n<br />";
56       
57    }
58 }
59
60
61 ?>