4 Ewiki nav bar plugin - by AndyFundinger
6 this plugin will create a navigation bar from a site map on a page. The site
7 map should be a list with wiki words or [] style wiki links. You must select
8 two functions to control the operation of your navigation bar.
9 $ewiki_plugins['select_navbar_buttons'][0] will be run to determine which
10 buttons are invisible($NavBar[$id][2] = 0), visible($NavBar[$id][2] = 1), or
11 active ($NavBar[$id][2] = 2). $ewiki_plugins['render_navbar_section'][0] will
12 control the actual rendering and is designed to support recursive calls. Two
13 versions of each are supported. You can also create your own site specific
14 selector or renderer. I use a function that calls
15 ewiki_navbar_selectall_buttons() to select the level 1 pages and then
16 ewiki_navbar_select_psuc() to select parents, siblings, uncles, and children if
19 The effect of this NavBar relies on stylesheets. You must add several classes
20 to make the NavBar appear properly. An example style sheet is
21 WikiNavBarStyle.css. The following tag will add this example style sheet to your
24 <link rel='stylesheet' href='./fragments/WikiNavBarStyle.css' type='text/css' media='all' />
26 The NavBar array is composed of one line per button as follows:
27 $NavBar[]=array( line text, depth, activation,target page);
29 Call mkLiveWebNavBar() from within your page to create a NavBar.
32 define("EWIKI_NAVBAR_SELECTALL_DEPTH",99);
33 define("EWIKI_NAVBAR_ACTIVATEPARENTS",1);
34 define("EWIKI_NAVBAR_ACTIVATECHILDREN",1);
35 define('EWIKI_NAVBAR_ACTION','view');
37 //Select only Parents, Siblings, Uncles, and Children
38 $ewiki_plugins['select_navbar_buttons'][]="ewiki_navbar_select_psuc";
39 //Select entire menu, highlight current page, selects to depth of
40 // EWIKI_NAVBAR_SELECTALL_DEPTH
41 $ewiki_plugins['select_navbar_buttons'][]="ewiki_navbar_selectall_buttons";
42 //Renders NavBar as a set of nested lists
43 $ewiki_plugins['render_navbar_section'][]='ewiki_render_navbar_list';
44 //Alternate render routine that puts sub bars below the major categories.
45 $ewiki_plugins['render_navbar_section'][]='ewiki_render_navbar_fixedtop_list';
47 //Create a navBar, call with a page to be turned into the bar and a page to be
48 // selected, uses $ewiki_plugins['select_navbar_buttons'][0] and
49 // $ewiki_plugins['render_navbar_section'][0]. Returns nothing if no bar is
51 function mkLiveWebNavBar($navBarPage, $activePage){
53 $data = ewiki_db::GET($navBarPage);
55 #-- Authenticate, return nothing if authentication fails
56 if (ewiki_auth($navBarPage, $data, EWIKI_NAVBAR_ACTION, $ring=3, $force=0)) {
60 #-- escape if navBarPage does not exist or was not retrieved.
61 if(empty($data["content"])){
64 //echo(":".$data["content"].":");
66 $o .= ewiki_navbar_format ( $data["content"], 1,urlencode($activePage) );
68 //Apply class only if we have a bar at all
70 return(" <div class='wikiNavBar' >\n".$o."\n</div>\n");
74 //An adaptation of ewiki_format to format navigation bars
75 function ewiki_navbar_format ($wiki_source, $scan_links=1,
76 $currpage=EWIKI_PAGE_INDEX)
78 global $ewiki_links, $ewiki_plugins;
80 //echo("navbar function run");
83 ewiki_scan_wikiwords($wiki_source, $ewiki_links);
89 // plugins only format finals are respected
90 $pf_final = @$ewiki_plugins["format_final"];
92 $table_defaults = 'cellpadding="2" border="1" cellspacing="0"';
93 $syn_htmlentities = array(
100 "-" => array('ul type="square"', "", "li"),
101 "*" => array('ul type="circle"', "", "li"),
102 "#" => array("ol", "", "li"),
103 ":" => array("dl", "dt", "dd"),
104 ";" => array("dl", "dt", "dd"),
108 foreach ($syn_htmlentities as $find=>$replace) {
109 $wiki_source = str_replace($find, $replace, $wiki_source);
111 array_pop($syn_htmlentities); // strips "&"
113 // add a last empty line to get opened tables/lists closed correctly
114 $wiki_source = trim($wiki_source) . "\n";
117 #-- finally the link-detection-regex
118 # (impossible to do with the simple string functions)
119 ewiki_render_wiki_links($wiki_source);
123 //return($wiki_source);
124 foreach (explode("\n", $wiki_source) as $line) {
126 $line = rtrim($line);
130 if ( strlen($line) && isset($wm_list[@$line[0]]) ) {
133 #-- count depth of list
134 # line has length first character in the line is in wm_list
135 while (strlen($line) && ('*'==$line[0]) ) {
136 $li .= '*'; //add new list delim to list count
138 $line = substr($line, 1); //remove first character
140 $line = ltrim($line);
142 $regex='#<a href=["\'](.*)'.preg_quote(EWIKI_SCRIPT) .'(.*?)["\'&?^](.*)#i';
143 preg_match($regex,$line,$matches=array());
146 //echo($regex.$line."HREF'".$href."'");
148 $NavBar[]=array($line,$n,0,$href);
149 //echo($line.$n.count($NavBar));
154 //$NavBar now contains all elements in the navigation bar.
158 $NavBar=$ewiki_plugins['select_navbar_buttons'][0]($NavBar,$currpage);
163 $barText=$ewiki_plugins['render_navbar_section'][0]($pre,$post,$NavBar);
164 $barText=$pre.$barText.$post;
166 //Cut out if we have no navigation bar
173 #-- international characters
174 if (EWIKI_HTML_CHARS) {
175 $o = str_replace("&#", "&#", $o);
179 #-- call post processing plugins
181 foreach ($pf_final as $pf) $pf($o);
188 //Select entire menu, highlight current page, selects to depth of
189 // EWIKI_NAVBAR_SELECTALL_DEPTH, or can be called with a specified depth.
190 function ewiki_navbar_selectall_buttons( $NavBar,$currpage,$maxlevel=EWIKI_NAVBAR_SELECTALL_DEPTH){
191 foreach($NavBar as $id=>$row){
192 //echo("($id,$currpage)");
193 if($row[1]>$maxlevel){
195 }elseif($row[3]==$currpage){
200 //echo("($id,$row[0],".$NavBar[$id][2].")");
205 //Selects parents, siblings, uncles and children
206 function ewiki_navbar_select_psuc( $NavBar,$currpage){
207 foreach($NavBar as $id=>$row){
208 //echo("($row[3],$currpage)");
209 if($row[3]==$currpage){
213 for($index=$id-1;$index>=0;$index--){
214 if($NavBar[$index][1]<=$selLev){
215 //set to displayed or active depending on ACTIVATEPARENTS
217 ((($NavBar[$index][1]==$selLev)||
218 (!EWIKI_NAVBAR_ACTIVATEPARENTS))? 1 : 2);
219 $selLev=$NavBar[$index][1]; //reduce selected level
224 for($index=$id+1;$index<count($NavBar);$index++){
225 //echo(":".$selLev.":(".$index.$NavBar[$index][0].$NavBar[$index][1].")");
227 if($NavBar[$index][1]<=$selLev){
228 if(!EWIKI_NAVBAR_ACTIVATECHILDREN){
229 $NavBar[$index][2]=1; //set to displayed
230 }elseif($NavBar[$index][1]==$row[1]+1){
231 $NavBar[$index][2]=2; //set to active
233 $NavBar[$index][2]=1; //set to displayed
235 $selLev=$NavBar[$index][1]; //reduce selected level
239 //echo($id.$NavBar[$id][2]);
244 //Render nav bar with sub menus appearing below entire bar
245 function ewiki_render_navbar_fixedtop_list($pre,$post,&$NavBar){
247 $element=current($NavBar);
248 $currLevel=$element[1];
249 //echo("processing".$currLevel.$uu[0]);
250 $myPre="<ul class='wikiNavBarDepth".$currLevel."'>";
253 if(($element[1]>$currLevel)){
254 $myPost.=ewiki_render_navbar_fixedtop_list($myPre,$myPost,$NavBar);
255 $element=current($NavBar);
257 }elseif($element[2]>=2){
258 $mySection.="<li class='activebutton'>".$element[0]."</li>";
259 }elseif($element[2]>=1){
260 $mySection.="<li class='inactivebutton'>".$element[0]."</li>";
262 //$mySection.=$element[0] ."($element[1],$element[2])";
264 $element=next($NavBar);
265 }while(($element[1]>=$currLevel));
267 //Return list if there are elements
269 return($myPre.$mySection.$myPost);
273 //Render nav bar as a simple list
274 function ewiki_render_navbar_list($pre,$post,&$NavBar){
276 $element=current($NavBar);
277 $currLevel=$element[1];
278 //echo("processing".$currLevel.$uu[0]);
279 $myPre="<ul class='wikiNavBarDepth".$currLevel."'>";
282 if(($element[1]>$currLevel)){
283 $mySection.=ewiki_render_navbar_list($myPre,$myPost,$NavBar);
284 $element=current($NavBar);
286 }elseif($element[2]>=2){
287 $mySection.="<li class='activebutton'>".$element[0]."</li>";
288 }elseif($element[2]>=1){
289 $mySection.="<li class='inactivebutton'>".$element[0]."</li>";
291 //$mySection.=$element[0] ."($element[1],$element[2])";
294 $element=next($NavBar);
295 }while(($element[1]>=$currLevel));
297 //Return list if there are elements
299 return($myPre.$mySection.$myPost);