eb4869e5dca39d163c7335a7c0f67966d3b90b9a
[atutor.git] / mods / wiki / plugins / mpi / mpi_localsitemap.php
1 <?php
2
3 /*
4    This mpi provides a tree of page backlinks from the current or any
5    given page, thus creating a sitemap.
6
7    <?plugin LocalSiteMap ?>
8    <?plugin LocalSiteMap page=ForThatPage depth=2 ?>
9
10    You shouldn't use depths greater than 3, else database walking would
11    take a while, and the result would be uglily long.
12 */
13
14 $ewiki_plugins["mpi"]["localsitemap"] = "mpi2_localsitemap";
15
16
17 function mpi2_localsitemap($action, $args, &$iii, &$s) {
18
19    ($depth = $args["depth"]) or ($depth = 2);
20    if ($depth > 5) {
21       $depth = 5;
22    }
23    ($id = $args["page"]) or ($id = $GLOBALS["ewiki_id"]);
24
25    $src = mpi2_localsitemap_revbl($id, "", $depth);
26
27
28    #-- throw output into _format() kernel buffer
29    if ($src) {
30       $c = &$iii[$s["in"]];
31       $c[0] = $src;
32       $c[1] = 0x00FF;
33       $c[2] = "core";
34    }
35    return($src);
36 }
37
38
39 function mpi2_localsitemap_revbl($id, $li, $depth) {
40    $src = "";
41    $li .= "*";
42    if ($depth--) {
43       if ($refs = ewiki_get_links($id)) {
44          foreach ($refs as $id) {
45             $src .= "$li [$id]\n";
46             $src .= mpi2_localsitemap_revbl($id, $li, $depth);
47          }
48       }
49    }
50    return($src);
51 }
52
53 ?>