a26d58153c6ea9be0fe790a0b7f7a340469b06db
[atutor.git] / mods / wiki / plugins / mpi / mpi_backtree.php
1 <?php
2
3 /*
4    This mpi provides a tree of page backlinks from the current or any
5    given page. It's the opposite of mpi_localsitemap.
6
7    <?plugin BackTree ?>
8    <?plugin BackTree 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"]["backtree"] = "mpi2_backtree";
15
16
17 function mpi2_backtree($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_backtree_revbl($id, "", $depth);
26
27    #-- throw output into _format() kernel buffer
28    if ($src) {
29       $c = &$iii[$s["in"]];
30       $c[0] = $src;
31       $c[1] = 0x00FF;
32       $c[2] = "core";
33    }
34    return($src);
35 }
36
37
38 function mpi2_backtree_revbl($id, $li, $depth) {
39    $src = "";
40    $li .= "*";
41    if ($depth--) {
42       if ($refs = ewiki_get_backlinks($id)) {
43          foreach ($refs as $id) {
44             $src .= "$li [$id]\n";
45             $src .= mpi2_backtree_revbl($id, $li, $depth);
46          }
47       }
48    }
49    return($src);
50 }
51
52 ?>