Change BSApi::remove() to BSApi::delete()
[isso.git] / PrinterNavigation.php
1 <?php
2 /*=====================================================================*\
3 || ###################################################################
4 || # Blue Static ISSO Framework
5 || # Copyright (c)2005-2008 Blue Static
6 || #
7 || # This program is free software; you can redistribute it and/or modify
8 || # it under the terms of the GNU General Public License as published by
9 || # the Free Software Foundation; version 2 of the License.
10 || #
11 || # This program is distributed in the hope that it will be useful, but
12 || # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 || # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 || # more details.
15 || #
16 || # You should have received a copy of the GNU General Public License along
17 || # with this program; if not, write to the Free Software Foundation, Inc.,
18 || # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
19 || ###################################################################
20 \*=====================================================================*/
21
22 /**
23 * Printer: Navigation Generator (PrinterNavigation.php)
24 *
25 * @package ISSO
26 */
27
28 /**
29 * Printer: Navigation Generator
30 *
31 * This framework works in conjunction with BSPrinter to generate a page header
32 * and sidebar to be used for navigation. You set the navigation array and then can
33 * specify a given key to highlight elements. Elements are broken into three types:
34 * tabs (top of the page), groups (blocks of link actions), and links
35 *
36 * @author Blue Static
37 * @copyright Copyright (c)2005 - 2008, Blue Static
38 * @package ISSO
39 *
40 */
41 class BSPrinterNavigation
42 {
43 /**
44 * XML document structure
45 * @var SimpleXMLElement
46 */
47 private $structure;
48
49 /**
50 * Keys to set focus on
51 * @var array
52 */
53 private $focusKeys = array();
54
55 /**
56 * Sections to display
57 * @var array
58 */
59 private $displaySections = array();
60
61 /**
62 * Constructor
63 *
64 * @param string Navigation XML data
65 */
66 public function __construct($xml)
67 {
68 $this->structure = new SimpleXMLElement($xml);
69 }
70
71 /**
72 * Adds focus to a given key
73 *
74 * @param string Key
75 */
76 public function addFocus($key)
77 {
78 if (sizeof($this->structure->xpath('//*[@key="' . $key . '"]')) != 1)
79 {
80 throw new Exception('The key passed to BSPrinterNavigation::addFocus() is either too vague or nonexistent');
81 }
82 $this->focusKeys[] = $key;
83 }
84
85 /**
86 * Adds a section to display. The order in which sections are added is the order
87 * in which they are painted
88 *
89 * @param string Key
90 */
91 public function addSection($key)
92 {
93 if (sizeof($this->structure->xpath('//*[@key="' . $key . '"]')) != 1)
94 {
95 throw new Exception('The key passed to BSPrinterNavigation::addSection() is either too vague or nonexistent');
96 }
97 $this->displaySections[] = $key;
98 }
99
100 /**
101 * Generates the header HTML that is called in BSPrinterRootPage
102 * to setup the navigation frame
103 *
104 * @return string Generated HTML content
105 */
106 public function constructHeaderHtml()
107 {
108 $output = '<!-- navigation start -->' . "\n\n";
109
110 // -------------------------------------------------------------------
111
112 if (isset($this->structure->links))
113 {
114 $links = array();
115 foreach ($this->structure->links->link as $link)
116 {
117 $attrs = $link->attributes();
118 $links[] = '<a href="' . $attrs->target . '">' . $link . '</a>';
119 }
120 }
121
122 $output .= "\n" . '<div id="toplinks">';
123 $output .= "\n\t" . '<div>' . BSPrinter::get_realm() . '</div>';
124 if (isset($links))
125 {
126 $output .= "\n\t" . '<div id="toplinks-links">' . implode(' &bull; ', $links) . '</div>';
127 }
128 $output .= "\n" . '</div>';
129
130 // -------------------------------------------------------------------
131
132 $output .= "\n\n" . '<div id="wrapper">';
133
134 // -------------------------------------------------------------------
135
136 if (isset($this->structure->tabs))
137 {
138 $output .= "\n" . '<div id="tabbar">';
139 foreach ($this->structure->tabs->tab as $tab)
140 {
141 $link = "\n\t" . '<a href="' . $tab['target'] . '"';
142 if (in_array($tab['key'], $this->focusKeys))
143 {
144 $link .= ' id="focustab"';
145 }
146
147 $link .= '><span>' . $tab . '</span></a>';
148
149 $output .= $link;
150 }
151 $output .= "\n" . '</div>';
152 }
153
154 // -------------------------------------------------------------------
155
156 $output .= "\n\n" . '<table id="contentbody" cellspacing="0" cellpadding="0" border="0">';
157 $output .= "\n" . '<tr>';
158
159 // -------------------------------------------------------------------
160
161 $output .= "\n" . '<td id="menu">';
162 foreach ($this->structure->sections->section as $section)
163 {
164 if (!in_array($section['key'], $this->displaySections))
165 {
166 continue;
167 }
168
169 // handle inherited sections
170 $links = array();
171 if ($section['inherits'])
172 {
173 $keys = explode(',', $section['inherits']);
174
175 foreach ($keys as $parKey)
176 {
177 $parLinks = $this->structure->xpath('/navigation/sections/section[@key="' . $parKey . '"]/link');
178 $links = array_merge($links, $parLinks);
179 }
180
181 // add the links from the hybrid section
182 if (is_array($section->link))
183 {
184 $links = array_merge($links, $section->link);
185 }
186 else
187 {
188 $links[] = $section->link;
189 }
190 }
191 // no inheritance, so the links are straight from the section
192 else
193 {
194 $links = $section->link;
195 }
196
197 $output .= "\n" . '<ul>';
198 $output .= "\n\t" . '<li class="header"><span>' . $section['name'] . '</span></li>';
199 foreach ($links as $link)
200 {
201 $output .= "\n\t" . '<li' . (in_array($link['key'], $this->focusKeys) ? ' class="focus"' : '') . '><a href="' . $link['target'] . '"><span>' . $link . '</span></a></li>';
202 }
203 $output .= "\n" . '</ul>' . "\n";
204 }
205 $output .= "\n" . '</td>';
206
207 // -------------------------------------------------------------------
208
209 $output .= "\n" . '<td id="mainbody">';
210 $output .= "\n\n" . '<!-- main content body -->' . "\n";
211
212 return $output;
213 }
214
215 /**
216 * Generates the HTML that is inserted in BSPrinterRootPage that
217 * closes all of the navigation HTML stuff
218 *
219 * @return string Generated HTML content
220 */
221 public function constructFooterHtml()
222 {
223 $output = '';
224
225 $output .= "\n" . '<!-- / main content body -->' . "\n";
226
227 $output .= "\n" . '</td>';
228 $output .= "\n" . '</tr>';
229
230 $output .= "\n\n" . '</table>';
231
232 $output .= "\n\n" . '</div>';
233
234 return $output;
235 }
236 }
237
238 ?>