]>
src.bluestatic.org Git - isso.git/blob - PrinterNavigation.php
2 /*=====================================================================*\
3 || ###################################################################
4 || # Blue Static ISSO Framework
5 || # Copyright (c)2005-2009 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 - 2009, 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 if (sizeof($this->structure
->xpath('//*[@key="' . $key . '"]')) != 1)
80 throw new Exception('The key passed to BSPrinterNavigation::addFocus() is either too vague or nonexistent');
82 $this->focusKeys
[] = $key;
86 * Adds a section to display. The order in which sections are added is the order
87 * in which they are painted
91 public function addSection($key)
93 if (sizeof($this->structure
->xpath('//*[@key="' . $key . '"]')) != 1)
95 throw new Exception('The key passed to BSPrinterNavigation::addSection() is either too vague or nonexistent');
97 $this->displaySections
[] = $key;
101 * Generates the header HTML that is called in BSPrinterRootPage
102 * to setup the navigation frame
104 * @return string Generated HTML content
106 public function constructHeaderHtml()
108 $output = '<!-- navigation start -->' . "\n\n";
110 // -------------------------------------------------------------------
112 if (isset($this->structure
->links
))
115 foreach ($this->structure
->links
->link
as $link)
117 $attrs = $link->attributes();
118 $links[] = '<a href="' . $attrs->target
. '">' . $link . '</a>';
122 $output .= "\n" . '<div id="toplinks">';
123 $output .= "\n\t" . '<div>' . BSPrinter
::get_realm() . '</div>';
126 $output .= "\n\t" . '<div id="toplinks-links">' . implode(' • ', $links) . '</div>';
128 $output .= "\n" . '</div>';
130 // -------------------------------------------------------------------
132 $output .= "\n\n" . '<div id="wrapper">';
134 // -------------------------------------------------------------------
136 if (isset($this->structure
->tabs
))
138 $output .= "\n" . '<div id="tabbar">';
139 foreach ($this->structure
->tabs
->tab
as $tab)
141 $link = "\n\t" . '<a href="' . $tab['target'] . '"';
142 if (in_array($tab['key'], $this->focusKeys
))
144 $link .= ' id="focustab"';
147 $link .= '><span>' . $tab . '</span></a>';
151 $output .= "\n" . '</div>';
154 // -------------------------------------------------------------------
156 $output .= "\n\n" . '<table id="contentbody" cellspacing="0" cellpadding="0" border="0">';
157 $output .= "\n" . '<tr>';
159 // -------------------------------------------------------------------
161 $output .= "\n" . '<td id="menu">';
162 foreach ($this->structure
->sections
->section
as $section)
164 if (!in_array($section['key'], $this->displaySections
))
169 // handle inherited sections
171 if ($section['inherits'])
173 $keys = explode(',', $section['inherits']);
175 foreach ($keys as $parKey)
177 $parLinks = $this->structure
->xpath('/navigation/sections/section[@key="' . $parKey . '"]/link');
178 $links = array_merge($links, $parLinks);
181 // add the links from the hybrid section
182 if (is_array($section->link
))
184 $links = array_merge($links, $section->link
);
188 $links[] = $section->link
;
191 // no inheritance, so the links are straight from the section
194 $links = $section->link
;
197 $output .= "\n" . '<ul>';
198 $output .= "\n\t" . '<li class="header"><span>' . $section['name'] . '</span></li>';
199 foreach ($links as $link)
201 $output .= "\n\t" . '<li' . (in_array($link['key'], $this->focusKeys
) ? ' class="focus"' : '') . '><a href="' . $link['target'] . '"><span>' . $link . '</span></a></li>';
203 $output .= "\n" . '</ul>' . "\n";
205 $output .= "\n" . '</td>';
207 // -------------------------------------------------------------------
209 $output .= "\n" . '<td id="mainbody">';
210 $output .= "\n\n" . '<!-- main content body -->' . "\n";
216 * Generates the HTML that is inserted in BSPrinterRootPage that
217 * closes all of the navigation HTML stuff
219 * @return string Generated HTML content
221 public function constructFooterHtml()
225 $output .= "\n" . '<!-- / main content body -->' . "\n";
227 $output .= "\n" . '</td>';
228 $output .= "\n" . '</tr>';
230 $output .= "\n\n" . '</table>';
232 $output .= "\n\n" . '</div>';