f5fc334bc6c7afd16593b81ffde73fb220704a42
[atutor.git] / mods / wiki / plugins / aview / toc.php
1 <?php
2
3 /*
4    Adds a CSS container with links to all listed headlines of the
5    current page (but threshold for its activation is 3).
6
7     .wiki .page-toc {
8        width: 160px;
9        float: right;
10        border: 2px #333333 solid;
11        background: #777777;
12     }
13
14    Modified 20040810 by Jochen
15    - makes now use of EWIKI_TOC_CAPTION to print "TOC" above it all
16    - indention swapped (biggest headlines are now left,
17      and smaller ones are indented to the right)
18    - added some \n for more readable html
19 */
20
21
22 #-- reg
23 $ewiki_plugins["format_source"][] = "ewiki_toc_format_source";
24 $ewiki_plugins["format_final"][] = "ewiki_toc_view_prepend";
25 define("EWIKI_TOC_CAPTION", 0);
26 $ewiki_t["en"]["toc"] = "Content";
27 $ewiki_t["de"]["toc"] = "Inhalt";
28
29
30 #-- wiki page source rewriting
31 function ewiki_toc_format_source(&$src) {
32
33    $toc = array();
34
35    $src = explode("\n", $src);
36    foreach ($src as $i=>$line) {
37
38       if ($line[0] == "!") {
39          $n = strspn($line, "!");
40          if (($n <= 3) and ($line[$n]==" ")) {
41
42             $text = substr($line, $n);
43             $toc[$i] = str_repeat("&nbsp;", 3-$n) . "ยท"
44                      .// Had top fix this to make anchor links in the TOC work '<a href="#line'.$i.'">
45                      '<a href="'.EWIKI_SCRIPT.$_GET['page'].'#line'.$i.'">'
46                      . trim($text) . "</a>";
47
48             $src[$i] = str_repeat("!", $n) . $text . " [#line$i]";
49
50          }
51       }
52    }
53    $src = implode("\n", $src);
54
55    $GLOBALS["ewiki_page_toc"] = &$toc;
56 }
57
58
59 #-- injects toc above page
60 function ewiki_toc_view_prepend(&$html) {
61
62    global $ewiki_page_toc;
63
64    if (count($ewiki_page_toc) >= 3) {
65
66       $html = "<div class=\"page-toc\">\n"
67          . ( EWIKI_TOC_CAPTION ? '<div class="page-toc-caption">'.ewiki_t("toc")."</div>\n" : '')
68          . implode("<br />\n", $ewiki_page_toc) . "</div>\n"
69          . $html;
70    }
71
72    // $ewiki_page_toc = NULL;
73 }
74
75
76 ?>