| core_html

# Class: Bs_HtmlNavigation Source Location: /core/html/Bs_HtmlNavigation.class.php
### Class Overview
    Bs_Object
       |
       --Bs_HtmlNavigation
HtmlNavigation class. #### Author(s): sam blum <at blueshoes dot org> andrej arn <at blueshoes dot org> #### Version: 4.5.$Revision: 1.8 $ $Date: 2003/12/27 16:05:36 $ #### Copyright: blueshoes.org | ### Variables $_data $_style | ### Methods Bs_HtmlNavigation debugData parseHeadFootStyle parseLinkStyle setCurrentPage setData setStyle toHtml _addParent _localEval _walkSibling _walkTreeDown _walkTreeUp
### Inherited Variables | ### Inherited Methods #### Class: Bs_Object Bs_Object::Bs_Object() Bs_Object::getErrors() Basic error handling: Get *all* errors as string array from the global Bs_Error-error stack. Bs_Object::getLastError() Basic error handling: Get last error string from the global Bs_Error-error stack. Bs_Object::getLastErrors() Basic error handling: Get last errors string array from the global Bs_Error-error stack sinc last call of getLastErrors(). Bs_Object::persist() Persists this object by serializing it and saving it to a file with unique name. Bs_Object::setError() Basic error handling: Push an error string on the global Bs_Error-error stack. Bs_Object::toHtml() Dumps the content of this object to a string using PHP's var_dump(). Bs_Object::toString() Dumps the content of this object to a string using PHP's var_dump(). Bs_Object::unpersist() Fetches an object that was persisted with persist()
### Class Details [line 64] HtmlNavigation class. Only 3 steps are needed to have your fully customized dynamic navigation: 1) give the navigation data (links) 2) specify the styles 3) specify the current page the user is looking at Uses styles, they may come from PHP arrays or XML files. the website for this class is at: http://www.blueshoes.org/en/framework/html/navigation/ Features: Every level of the navigation can have it's own style definitions. The placeholders __LINK__, __KEY__, __URL__, __TARGET__, __CAPTION__, __CAPTION_UPPER__, __CAPTION_LOWER__ and __CAPTION_URLENCODE__ can be used, as well as user defined placeholders that must start wirh __MY_ Navigation elements can look different based on the currently active page. The current active page can be 'self', 'sibling', 'parent' or 'child' of the element. PHP code can be used in link definition styles for maximum flexibility that gets executed on run-time. example for copy/paste: (see the website) $n =& new Bs_HtmlNavigation(); $n->setStyle($navStyle); $n->setData($navData); $n->setCurrentPage($bsEnv['requestPath']); //use $_SERVER['PHP_SELF'] or so. echo $n->toHtml(); dependencies: none #### Tags:
version: | 4.5.$Revision: 1.8 $ $Date: 2003/12/27 16:05:36 $
copyright: | blueshoes.org
author: | sam blum <at blueshoes dot org>
author: | andrej arn <at blueshoes dot org>
[ Top ] ### Class Variables #### $_data = [line 73] special cases: hash keys 'id', 'active' and 'parent' will be added (partly). see code for details. used internally only anyway. #### Tags:
see: | Bs_HtmlNavigation::setData()
Type: | array
[ Top ] #### $_style = [line 135] the style information. it's a structured array (hash), like this: 'head' => gets added on top of the navigation. example: "nav starts here" 'foot' => gets added at the end of the navigation. 'empty' => gets spitted out if there is no navigation data. then even 'head' and 'foot' are ignored. example: "no navigation data" 'level' => container for the levels that follow now. '1' => container for level 1. it can be any number, eg '2' would be level 2. '3+' means 'all levels starting at 3, and above'. '3-7' means all levels from 3 to 7 (including 3 and 7). no other special cases (there is no '-7' to say 'everything from 1 to 7). levels start at number 1, not 0. 'head' => gets added on top of every navigation entry for that level. example: "nbsp;nbsp;nbsp;" (to indent 3 spaces). 'foot' => gets added at the end of every navigation entry for that level. example: " " (to add a line break). 'linkFormat' => you can overwrite the default <a href ...> code. 'link' => container for the link itself. 'default' => navigation link. example: "__LINK__" the default is used ... todo finish that documentation. 'children' => used if set and the element has children. 'defaultActive' => same as default, plus this link is currently active. 'childrenActive' => same as children, plus this link is currently active. 'childrenActiveSelf' 'defaultActiveSelf' 'childrenActiveSibling' 'defaultActiveSibling' 'childrenActiveChild' 'defaultActiveChild' __LINK__ is a placeholder for <a href="__URL__">__CAPTION__</a> __URL__ is a placeholder for your url, eg http://www.blueshoes.org/ __KEY__ is a placeholder for the key (if not given url is used) __TARGET__ is a placeholder for your url target, eg _blank, _self, _top, ... __CAPTION__ is a placeholder for your navigation caption, eg "blueshoes homepage" __CAPTION_UPPER__ is a __CAPTION__, in uppercase __CAPTION_LOWER__ is a __CAPTION__, in lowercase __CAPTION_URLENCODE__ is a __CAPTION__ with rawurlencode() applied __MY_foo is a placeholder for your passed variable(s) in the data tree. The key must start with '__MY_' as prefix. See sample below. note: you can even use php code in your link definition strings! (woohoo :) the following vars are usable in that scope: $level => int, the level you're in $style => todo $data => todo $dataElement => todo $styleElement => todo example: 'default' => '<tr><td><? php for ($i=1; $i<$level; $i++) { echo "&nbsp;"; }? >__LINK__</td></tr>' note: replace the spaces in "<? php" and "? >". i had to add them so my editor does not freak out. also see _setDefaultStyle() for a simple example. #### Tags:
var: | (hash, see above)
see: | _setDefaultStyle()
Type: | array
[ Top ] ### Class Methods ### constructor Bs_HtmlNavigation [line 150]
`Bs_HtmlNavigation Bs_HtmlNavigation( )`
Constructor [ Top ] ### method debugData [line 247]
`void debugData( array $data, [string $prefix = ''])`
debug function. shows the nav data in a tree. uses echo. #### Tags:
access: | public
#### Parameters:
array | $data | (use $this->_data)
string | $prefix | (used internally only)
[ Top ] ### method parseHeadFootStyle [line 545]
`void parseHeadFootStyle( mixed $style, mixed $parentId)`
[ Top ] ### method parseLinkStyle [line 499]
`string parseLinkStyle( string $linkStyle, array $data, [string $linkFormat = NULL], [string $noLinkFormat = NULL])`
creates a navigation element with the given style and data. used internally, feel free to use it from outside this class. example: parseLinkStyle("__LINK__", array('caption'=>'blueshoes', 'url'=>'http://www.blueshoes.org/')); will return blueshoes the special strings may be used in the $linkStyle param: __LINK__ __URL__ __TARGET__ __CAPTION__ __CAPTION_UPPER__ __CAPTION_LOWER__ __CAPTION_URLENCODE__ __MY_* e.g. '__MY_foo' => Free user data #### Tags:
access: | public
#### Parameters:
string | $linkStyle |
array | $data | (hash)
string | $linkFormat |
string | $noLinkFormat |
[ Top ] ### method setCurrentPage [line 232]
`void setCurrentPage( string $requestUrl)`
sets which page is currently active (been viewed by the user). Pass the menu key used in in the passed data tree OR (if *no* 'key' was given) use the url. Something like "/path/to/file.html?foo=bar". (Remember we use the url as falback key, if no key was given in the data tree) #### Tags:
access: | public
#### Parameters:
string | $requestUrl |
[ Top ] ### method setData [line 215]
`void setData( array $data)`
sets the navigation data. example array structure of $data: $data = array( => array( 'key' => 'id_php', // optional (but recommended), you may deffine your own key as ID ... 'url' => 'http://www.php.net/', // ... otherwise the url, is used as ID if 'key' is empty 'caption' => 'php', 'target' => '_blank' '__MY_foo' => 'user data' // Free user data (but key must start with '__MY_) ) ) ) ); so it's a structured array with [some] of the keys 'caption' => text to display. must have. can be html code like <img src="imageWithTextThatLooksBetterThanPlainText.gif"> 'key' => optional (but recommended), you may deffine your own key as ID, if empty the 'url' is used as key 'url' => url to link to. not specifield = no link. 'target' => where to link 'url' to. not specified = '_self'. 'children' => array with children of that element. '__MY_foo' => Free user data (but key must start with '__MY_) defaultActive defaultActiveSelf defaultActiveSibling defaultActiveChild defaultActiveParent childrenActive childrenActiveSelf childrenActiveSibling childrenActiveChild childrenActiveParent that example creates a nav like this: blueshoes homepage php this method also sets a unique id for each element. #### Tags:
access: | public
#### Parameters:
array | $data | (vector, see above)
[ Top ] ### method setStyle [line 416]
`void setStyle( array $style)`
sets the styles #### Tags:
see: | var $_style
access: | public
#### Parameters:
array | $style | (hash)
[ Top ] ### method toHtml [line 863]
`string toHtml( )`
returns the navigation as html output #### Tags:
return: | (html, may be an empty string.)
access: | public
Overrides Bs_Object::toHtml() (Dumps the content of this object to a string using PHP's var_dump().) [ Top ] ### method _addParent [line 395]
`void _addParent( array &$data, array &$parent)`
helper function that calls itself recursively to add the link back to the parent array element (as reference). #### Parameters:
array | &$data |
array | &$parent | (passed by ref, used internally)
[ Top ] ### method _localEval [line 827]
`void _localEval( mixed $str)`
[ Top ] ### method _walkSibling [line 349]
`void _walkSibling( mixed &$arr, [mixed $what = 'sibling'])`
see _locateCurrentPage() [ Top ] ### method _walkTreeDown [line 334]
`void _walkTreeDown( mixed &$arr)`
see _locateCurrentPage() [ Top ] ### method _walkTreeUp [line 321]
`void _walkTreeUp( mixed &$arr)`
see _locateCurrentPage() [ Top ] Documentation generated on Mon, 29 Dec 2003 21:10:55 +0100 by phpDocumentor 1.2.3