2 /*=====================================================================*\
3 || ###################################################################
4 || # Blue Static ISSO Framework
5 || # Copyright (c)2005-2008 Blue Static
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.
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
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 \*=====================================================================*/
23 * Printer: Navigation Generator (PrinterNavigation.php)
29 * Printer: Navigation Generator
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
37 * @copyright Copyright (c)2005 - 2008, Blue Static
41 class BSPrinterNavigation
44 * XML document structure
45 * @var SimpleXMLElement
50 * Keys to set focus on
53 private $focusKeys = array();
59 private $displaySections = array();
64 * @param string Navigation XML data
66 public function __construct($xml)
68 $this->structure
= new SimpleXMLElement($xml);
72 * Adds focus to a given key
76 public function addFocus($key)
78 $this->focusKeys
[] = $key;
82 * Adds a section to display. The order in which sections are added is the order
83 * in which they are painted
87 public function addSection($key)
89 $this->displaySections
[] = $key;
93 * Generates the header HTML that is called in BSPrinterRootElementPage
94 * to setup the navigation frame
96 * @return string Generated HTML content
98 public function constructHeaderHtml()
100 $output = '<!-- navigation start -->' . "\n\n";
102 // -------------------------------------------------------------------
104 if (isset($this->structure
->links
))
107 foreach ($this->structure
->links
->link
as $link)
109 $attrs = $link->attributes();
110 $links[] = '<a href="' . $attrs->target
. '">' . $link . '</a>';
114 $output .= "\n" . '<div id="toplinks">';
115 $output .= "\n\t" . '<div>' . BSPrinter
::get_realm() . '</div>';
118 $output .= "\n\t" . '<div id="toplinks-links">' . implode(' • ', $links) . '</div>';
120 $output .= "\n" . '</div>';
122 // -------------------------------------------------------------------
124 $output .= "\n\n" . '<div id="wrapper">';
126 // -------------------------------------------------------------------
128 if (isset($this->structure
->tabs
))
130 $output .= "\n" . '<div id="tabbar">';
131 foreach ($this->structure
->tabs
->tab
as $tab)
133 $link = "\n\t" . '<a href="' . $tab['target'] . '"';
134 if (in_array($tab['key'], $this->focusKeys
))
136 $link .= ' id="focustab"';
139 $link .= '><span>' . $tab . '</span></a>';
143 $output .= "\n" . '</div>';
146 // -------------------------------------------------------------------
148 $output .= "\n\n" . '<table id="contentbody" cellspacing="0" cellpadding="0" border="0">';
149 $output .= "\n" . '<tr>';
151 // -------------------------------------------------------------------
153 $output .= "\n" . '<td id="menu">';
154 foreach ($this->structure
->sections
->section
as $section)
156 if (!in_array($section['key'], $this->displaySections
))
161 // handle inherited sections
163 if ($section['inherits'])
165 $keys = explode(',', $section['inherits']);
167 foreach ($keys as $parKey)
169 $parLinks = $this->structure
->xpath('/navigation/sections/section[@key="' . $parKey . '"]/link');
170 $links = array_merge($links, $parLinks);
173 // add the links from the hybrid section
174 if (is_array($section->link
))
176 $links = array_merge($links, $section->link
);
180 $links[] = $section->link
;
183 // no inheritance, so the links are straight from the section
186 $links = $section->link
;
189 $output .= "\n" . '<ul>';
190 $output .= "\n\t" . '<li class="header"><span>' . $section['name'] . '</span></li>';
191 foreach ($links as $link)
193 $output .= "\n\t" . '<li' . (in_array($link['key'], $this->focusKeys
) ?
' class="focus"' : '') . '><a href="' . $link['target'] . '"><span>' . $link . '</span></a></li>';
195 $output .= "\n" . '</ul>' . "\n";
197 $output .= "\n" . '</td>';
199 // -------------------------------------------------------------------
201 $output .= "\n" . '<td id="mainbody">';
202 $output .= "\n\n" . '<!-- main content body -->' . "\n";
208 * Generates the HTML that is inserted in BSPrinterRootElementPage that
209 * closes all of the navigation HTML stuff
211 * @return string Generated HTML content
213 public function constructFooterHtml()
217 $output .= "\n" . '<!-- / main content body -->' . "\n";
219 $output .= "\n" . '</td>';
220 $output .= "\n" . '</tr>';
222 $output .= "\n\n" . '</table>';
224 $output .= "\n\n" . '</div>';