1<?php
2// (c) Copyright by authors of the Tiki Wiki CMS Groupware Project
3//
4// All Rights Reserved. See copyright.txt for details and a complete list of authors.
5// Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details.
6// $Id$
7
8/** \file
9 * \brief Browse a tree, for example a categories tree
10 *
11 * \author zaufi@sendmail.ru
12 * \enhanced by luci@sh.ground.cz
13 *
14 */
15require_once('lib/tree/tree.php');
16
17/**
18 * \brief Class to render categories browse tree
19 */
20class BrowseTreeMaker extends TreeMaker
21{
22	/// Generate HTML code for tree. Need to redefine to add javascript cookies block
23	function make_tree($rootid, $ar)
24	{
25		$headerlib = TikiLib::lib('header');
26
27		$r = '<ul class="tree root">' . "\n";
28
29		$r .= $this->make_tree_r($rootid, $ar) . "</ul>\n";
30
31		// java script block that opens the nodes as remembered in cookies
32		$headerlib->add_jq_onready('setTimeout(function () {$(".tree.root:not(.init)").browse_tree().addClass("init")}, 100);');
33
34		// return tree
35		return $r;
36	}
37
38	//
39	// Change default (no code 'cept user data) generation behaviour
40	//
41	// Need to generate:
42	//
43	// [indent = <tabulator>]
44	// [node start = <li class="treenode">]
45	//  [node data start]
46	//   [flipper] +/- link to flip
47	//   [node child start = <ul class="tree">]
48	//    [child's code]
49	//   [node child end = </ul>]
50	//  [node data end]
51	// [node end = </li>]
52	//
53	//
54	//
55	function indent($nodeinfo)
56	{
57		return "\t\t";
58	}
59
60	function node_start_code_flip($nodeinfo, $count = 0)
61	{
62		return "\t" . '<li class="treenode withflip ' . (($count % 2) ? 'odd' : 'even') . '">';
63	}
64
65	function node_start_code($nodeinfo, $count = 0)
66	{
67		return "\t" . '<li class="treenode ' . (($count % 2) ? 'odd' : 'even') . '">';
68	}
69
70	//
71	function node_flipper_code($nodeinfo)
72	{
73		return '';
74	}
75
76	//
77	function node_data_start_code($nodeinfo)
78	{
79		return '';
80	}
81
82	//
83	function node_data_end_code($nodeinfo)
84	{
85		return "\n";
86	}
87
88	//
89	function node_child_start_code($nodeinfo)
90	{
91		global $prefs;
92
93		if ($this->node_cookie_state($nodeinfo['id']) != 'o' && $prefs['javascript_enabled'] === 'y') {
94			$style = ' style="display:none;"';
95		} else {
96			$style = '';
97		}
98
99		return '<ul class="tree" data-id="' . $nodeinfo['id'] .
100				   '" data-prefix="' . $this->prefix . '"' . $style . '>';
101	}
102
103	//
104	function node_child_end_code($nodeinfo)
105	{
106		return '</ul>';
107	}
108
109	//
110	function node_end_code($nodeinfo)
111	{
112		return "\t" . '</li>';
113	}
114}
115