4 # Generates a page tree from the currently viewed page up to
5 # the "root_page" and prints it below the EditThisPage-line.
6 # Usually this "root_page" is the same as the FrontPage of
7 # your Wiki (EWIKI_PAGE_INDEX), but this can be overriden with
8 # $ewiki_config["root_page"] or EWIKI_LINKTREE_DEST.
10 # Modified by AndyFundinger (http://erfurtwiki.sourceforge.net/?id=AndyFundinger)
13 define("EWIKI_LINKTREE_UL", 0); // else a link::list will be printed
16 $ewiki_plugins["view_append"][] = "ewiki_view_append_linktree";
20 function ewiki_view_append_linktree($id, $data, $action) {
23 $refs = ewiki_db::GETALL(array("refs"));
24 $refs = ewiki_f_parent_refs($refs);
27 if (empty($ewiki_config["root_page"])) {
28 if (defined("EWIKI_LINKTREE_DEST")) {
29 $ewiki_config["root_page"] = EWIKI_LINKTREE_DEST;
32 $ewiki_config["root_page"] = EWIKI_PAGE_INDEX;
35 $dest = &$ewiki_config["root_page"];
38 $paths = array($id=>$id);
41 * $paths["Current"] = "Current";
42 * $paths["WorldWideWeb\nWikiWikiWeb\nErfurtWiki"] = "ErfurtWiki";
45 #-- retry until at least one $path is found
46 while ( (!in_array($dest, $paths)) && ($depth <= 15) && (count($paths)<=100000)) {
50 #-- expand every last path entry
51 foreach ($paths as $pathkey=>$uu) {
53 #-- mk subkey from pathkey
54 if ($p = strrpos($pathkey, "\n")) {
55 $lkey = substr($pathkey, $p+1);
62 if ($walk = $refs[$lkey]) {
63 foreach ($walk as $add=>$uu) {
64 $paths[$pathkey."\n".$add] = $add;
72 foreach ($paths as $key => $name) {
74 $tree = array_reverse(explode("\n", $key));
75 $GLOBALS["ewiki_page_sections"] = array();
77 if (($name == $dest) && (count($tree) >= 2)) {
79 $GLOBALS["ewiki_page_sections"][] = $tree[1];
81 if (EWIKI_LINKTREE_UL) {
82 $o .= ewiki_f_tree($tree, 0);
84 $o .= ewiki_f_tree2($tree, 0);
90 ($o) && ($o = "<div class=\"link-tree\">$o</div>\n");
97 #-- outputs the given pages in a treelist
98 function ewiki_f_tree(&$pages, $n=1) {
100 if ($id = $pages[0]) {
103 $o .= ($n ? "<li>" : "") .
104 '<a href="'.ewiki_script("",$id).'">'.$id.'</a>' .
105 ($n ? "</li>" : "") . "\n";
106 $o .= ewiki_f_tree(array_slice($pages, 1));
114 #-- outputs a flat link list
115 function ewiki_f_tree2(&$pages, $n=1) {
117 foreach ($pages as $id) {
118 $o[] = '<a href="'.ewiki_script("",$id).'">'.$id.'</a>';
121 // "::" instead of "→" may also look nice
122 return(implode(" → ", $o) . "<br />");
127 #-- build parents array of (reverse) string $refs from the database
128 function ewiki_f_parent_refs($refs) {
133 while ($row = $refs->get()) {
134 $parent = $row["id"];
135 foreach (explode("\n", $row["refs"]) as $page) {
138 $pages[$page][$parent]=1;
141 //echo("($page,$parent) ");