Category Tree
Hey,
I started playing with TikiWiki just recently and liking what I saw. One thing I'm still looking for, though, is a more prominent way to navigate categories. In fact, I've decided, I'd like the navigation on the left to simply consist of the categories rather than the system menu. This will promote the kind of organization I want for our Intranet.
Since no one seems to have wanted this feature before, I decided to try hacking my own plugin. I've never done anything with php before, but it looked like I could mostly just copy code from tiki-browse_categories.php.
I thought I had it almost done, but it seems like I'm missing some basic concepts about how scope of variables work and stuff. The same code that works in tiki-browse_categories.php will not work when it's called from my wikiplugin_cattree function.
First I stripped most of the code from tiki-browse_categories.php, leaving just the stuff that showed the tree of categories. I saved the file (after backing it up and all) and just viewed it by clicking on "categories" in tiki. I got this working where it properly showed the tree, with expandable branches and everything, but without showing the rest of tiki.
Then I made it into a plugin like this:
function wikiplugin_cattree($data, $params) { require_once('tiki-setup.php'); include_once('lib/categories/categlib.php'); include_once('lib/tree/categ_browse_tree.php'); // Check for parent category or set to 0 if not present if(!isset($_REQUEST["parentId"])) { $_REQUEST["parentId"]=0; } // If the parent category is not zero get the category path if($_REQUEST["parentId"]) { $path = $categlib->get_category_path_browse($_REQUEST["parentId"]); $info = $categlib->get_category($_REQUEST["parentId"]); $description = $info["description"]; $father = $info["parentId"]; } else { $path = tra("TOP"); $description = ""; $father = 0; } // Convert $childrens //$debugger->var_dump('$children'); $ctall = $categlib->get_all_categories_ext(); //get_all_categories() is obsolete by now? $tree_nodes = array(); foreach ($ctall as $c) { $tree_nodes[] = array("id"=>$c["categId"], "parent"=>$c["parentId"], "data"=>''.$c["name"].''); } $tm = new CatBrowseTreeMaker("categ"); $out = $tm->make_tree($_REQUEST["parentId"], $tree_nodes); return ''.$out.''; }
The funny thing is, all that code that worked fine by itself would not work when called as a plugin. It told me:
Then I added These lines to the top:
That fixed the error above, but now I have this message:
With a little investigation, I've found that categorize.php is not called from any of the files included by my plugin. I've also found that if I generate an error on the last line of my function, the categorize.php error gets displayed after my function's error.
I'm feeling rather disoriented. I don't know if I needtroubleshooting help or if I need to be filled in on some basic principles that I'm breaking. Does anyone have any pointers?
This little feature would be a big boon to our Intranet, and it seems like it would be handy for other Tiki users as well. Thanks for taking time to decipher my post--and passing on any counsel.
Jonathan