=====CategoryTree===== At the time only a dirty hack to show categories as a tree, initiated by LeOn, converted into a plugin by FaKn The plain structure on Wikis allows to generate a lot of connected pages fast and simple. The navigation in the Wiki is as simple as using internet - with links. But after 5-6 steps I cannot remember, why I'm at the actually opened page. For me it is helpful to have an hierarchical tree with the structure of the Wiki. The idea was also to use the Category-system of Wikka (CategoryCategory and so on) to automatically generated tree. The results are presented [[http://www.net4lawyer.com/openlaw | here]]. **To do**: 1) Function to follow the navigation with the tree If i open a page, that has an place in the tree, i would like to find it and show the tree open at the right place... 2) More precise documentation. ====Implementation for Wikka 1.2==== Save the following as plugins/actions/categorytree.php %%(php;1) GetThemePath()."/images/"; $txt = ""; $txt .= ""; $txt .= ""; if (!(isset($_SESSION["tree"]))) { $_SESSION["active"] = array(); f_action_categorytree_get_level($wakka, 1, "CategoryCategory"); } else { if (isset($_GET["active1"])) { // call this recursive function for grab the tree $_SESSION["tree"] = ""; $_SESSION["active"] = array(); f_action_categorytree_get_level($wakka, 1, "KategorieKategorie"); } else { // get the tree from session variable // nothing necessary - the Text is saved in the session variable } } $txt .= $_SESSION["tree"]."
"; $txt .= ""; $txt .= " Proszę wybrać kategorię:
"; return $txt; } function f_action_categorytree_is_parent ($name) { if (preg_match("/^Category(.*)/i", $name)) return true; else return false; } function f_action_categorytree_get_level($wakka, $level, $parent = "CategoryCategory") { // little function for checking, if a category member is a category // or not (then it is an simple page) $txt = $_SESSION["tree"]; // the text is saved in the session variable "tree" $active = $_SESSION["active"]; $last = $_SESSION["last"]; $imgpath = $wakka->GetThemePath()."/images/"; $page = $parent; if ($wakka->CheckMySQLVersion(4,0,1)) $results = $wakka->FullCategoryTextSearch($page); else $results = $wakka->FullTextSearch($page); if ($results) { //$txt .= ""; $count = 0; $pagecount = 0; $list = array(); $active[$level] = $_GET["active".$level]; foreach ($results as $i => $cpage) { if($cpage['tag'] != $page) { array_push($list,$cpage['tag']); } } sort($list); while (list($key, $val) = each($list)) { //echo $key."; ".$val; $count++; $addin = ""; // control about the "addin" = pictures before the element // in the tree - on levels under the first one for ($x = 1; $x < $level; $x = $x+1) { if ($last[$x] == 1) {//count($list)) { $addin .= ""; } else { $addin .= ""; } } $title = $val; $nazwa = $val; // preparing links for the tree elements $myhref = "wakka=".$val; for ($y = 1; $y <= $level; $y = $y+1) { //echo $active[$y].";"; if ($y == $level) { $myhref .= "&active".$y."=".$val; } else { $myhref .= "&active".$y."=".$active[$y]; } } if (f_action_categorytree_is_parent($val)) { // if element has children if ($count == count($list)) { // if last element on this level if ($active[$level] == $val) { $pic1 = "menu_corner_minus"; $pic2 = "ksiazka_otw"; } else { $pic1 = "menu_corner_plus"; $pic2 = "ksiazka_zamk"; } $last[$level] = 1; } else { if ($active[$level] == $val) { $pic1 = "menu_tee_minus"; $pic2 = "ksiazka_otw"; } else { $pic1 = "menu_tee_plus"; $pic2 = "ksiazka_zamk"; } $last[$level] = 0; } } else { // this elements doesn't have children (= categories without subcategories) if (count($list) == $key+1) { // last empty element $pic1 = "menu_corner"; $pic2 = "stronica"; } else { // not last, regular tree element $pic1 = "menu_tee"; $pic2 = "stronica"; } } $myA = ""; $txt .= ""; // read next level, if necessary - but before that put some // variables into session variables $_SESSION["tree"] = $txt; $_SESSION["last"] = $last; $_SESSION["active"] = $active; if (($val == $active[$level]) and (f_action_categorytree_is_parent($val))) { f_action_categorytree_get_level($wakka, $level+1, $active[$level]); } $active = $_SESSION["active"]; $txt = $_SESSION["tree"]; $last = $_SESSION["last"]; $pagecount++; } } else $txt .= 'Sorry, no items found for ' . $page .'.'; $_SESSION["last"] = $last; $_SESSION["active"] = $active; $_SESSION["tree"] = $txt; } } print f_action_categorytree_get_tree($this); ?>%% Create a new custom theme (if you have not done this yet) by copying e.g. the 'light' theme from the 'templates' folder into 'plugins/templates'. Append the following at the end of header.php %%(php)
Action('categoriestree') ?>
%% Now you only need some images (for example you can download all needed files here: http://www.polskieustawy.com/pics/tree/) and manipulations on wikka.css to see the right tree generated from your categories. A simple addition to your copy of light.css is: %%(css) #tree { border-right: 1px solid #DDD; width: 200px; padding: 10px 10px 10px 10px; float: left; }%% Finally, switch to the new theme (either via your User settings or in the config, see http://docs.wikkawiki.org/WikkaThemes for more info). ====Implementation for Wikka 1.1.6.3==== This is the old code that works without plugins and templates: replace the line 1336 in Wakka.Class.php %%(php) print($this->Header().$this->Method($this->method).$this->Footer()); %% with this code: %%(php) $lBody = "
".$addin; $txt .= $myA.""; $txt .= $myA." "; if ($val == $_GET["wakka"]) { $txt .= " ".$myA.$nazwa.""; } else { $txt .= " ".$myA.$nazwa.""; } $txt .= "
".$this->getTree()." ".$this->Method($this->method).$this->Footer()."
"; print($this->Header().$lBody); %% Then add following functions to the Wakka-class (in the same file Wakka.Class.php): %%(php;1) function getTree () { $imgpath = "images/"; $txt = ""; $txt .= ""; $txt .= ""; if (!(isset($_SESSION["tree"]))) { $_SESSION["active"] = array(); $this->getLevel(1, "CategoryCategory"); } else { if (isset($_GET["active1"])) { // call this recursive function for grab the tree $_SESSION["tree"] = ""; $_SESSION["active"] = array(); $this->getLevel(1, "CategoryCategory"); } else { // get the tree from session variable // nothing necessary - the Text is saved in the session variable } } $txt .= $_SESSION["tree"]."
"; $txt .= ""; $txt .= " Proszę wybrać kategorię:
"; return $txt; } function isParent ($name) { if (preg_match("/^Category(.*)/i", $name)) return true; else return false; } function getLevel($level, $parent = "CategoryCategory") { // little function for checking, if a category member is a category // or not (then it is an simple page) $txt = $_SESSION["tree"]; // the text is saved in the session variable "tree" $active = $_SESSION["active"]; $last = $_SESSION["last"]; $imgpath = "images/"; $page = $parent; if ($this->CheckMySQLVersion(4,0,1)) $results = $this->FullCategoryTextSearch($page); else $results = $this->FullTextSearch($page); if ($results) { //$txt .= ""; $count = 0; $pagecount = 0; $list = array(); $active[$level] = $_GET["active".$level]; foreach ($results as $i => $cpage) { if($cpage['tag'] != $page) { array_push($list,$cpage['tag']); } } sort($list); while (list($key, $val) = each($list)) { //echo $key."; ".$val; $count++; $addin = ""; // control about the "addin" = pictures before the element // in the tree - on levels under the first one for ($x = 1; $x < $level; $x = $x+1) { if ($last[$x] == 1) {//count($list)) { $addin .= ""; } else { $addin .= ""; } } $title = $val; $nazwa = $val; // preparing links for the tree elements $myhref = "wakka=".$val; for ($y = 1; $y <= $level; $y = $y+1) { //echo $active[$y].";"; if ($y == $level) { $myhref .= "&active".$y."=".$val; } else { $myhref .= "&active".$y."=".$active[$y]; } } if ($this->isParent($val)) { // if element has children if ($count == count($list)) { // if last element on this level if ($active[$level] == $val) { $pic1 = "menu_corner_minus"; $pic2 = "ksiazka_otw"; } else { $pic1 = "menu_corner_plus"; $pic2 = "ksiazka_zamk"; } $last[$level] = 1; } else { if ($active[$level] == $val) { $pic1 = "menu_tee_minus"; $pic2 = "ksiazka_otw"; } else { $pic1 = "menu_tee_plus"; $pic2 = "ksiazka_zamk"; } $last[$level] = 0; } } else { // this elements doesn't have children (= categories without subcategories) if (count($list) == $key+1) { // ostatni pusty $pic1 = "menu_corner"; $pic2 = "stronica"; } else { // not last, regular tree element $pic1 = "menu_tee"; $pic2 = "stronica"; } } $myA = ""; $txt .= ""; // read next level, if necessary - but before that put some // variables into session variables $_SESSION["tree"] = $txt; $_SESSION["last"] = $last; $_SESSION["active"] = $active; if (($val == $active[$level]) and ($this->isParent($val))) { $this->getLevel($level+1, $active[$level]); } $active = $_SESSION["active"]; $txt = $_SESSION["tree"]; $last = $_SESSION["last"]; $pagecount++; } } else $txt .= 'Sorry, no items found for ' . $page .'.'; $_SESSION["last"] = $last; $_SESSION["active"] = $active; $_SESSION["tree"] = $txt; } %% Now you need only some images (for example you can download all needed files here: http://www.polskieustawy.com/pics/tree/) and manipulations on wikka.css to see the right tree generated from your categories. To be continued!
".$addin; $txt .= $myA.""; $txt .= $myA." "; if ($val == $_GET["wakka"]) { $txt .= " ".$myA.$nazwa.""; } else { $txt .= " ".$myA.$nazwa.""; } $txt .= "