{NAV_LIST_LEVEL:parent_level:class}

Post custom hacks and enhancements for phpwcms here only. Maybe some of these things will be included in official release later.
Post Reply
super ü
Posts: 6
Joined: Wed 28. Apr 2004, 12:47

{NAV_LIST_LEVEL:parent_level:class}

Post by super ü »

Hey Boys,

first of all, you guys do great things here, and a pocket full of glory to the Developer and the fit ones!

I just started working with phpWCMS and at the moment I´m trying to get the possibilities of Navigation Customizing.
I think it would be handy to have a Replacment Tag like

{NAV_LIST_LEVEL:parent_level:class}

so you can specify the output of a menu at every position from every positon in the level structure. I also wanted to have an "_active" id on the List Item which is currently selected.
My solution to that is pretty poor because I just look if $level is the same as given $parent_level.
If it is possible to detect the currently selected level depending on the given parent_level it would be much more flexible ...

Code:

front.func.inc.php

Code: Select all

function css_list_level($struct, $struct_path, $level, $parent_level=0, $class="list_level") {
	// returns list <div><ul><li></li></ul></div> of the structure level down from given parent_level
	// predefined class for this menu is "list_level"	
	
	if(!trim($class)) $class = "list_level";
	$parent_level_name = trim($parent_level_name);
	$level = intval($level);
	$parent_level = intval($parent_level);
	$activated = 0; //no active list set
	$css_list = "";
	
	//returns the complete level of NON hidden categories
	$level_struct = return_struct_level($struct, $parent_level); 

	if(sizeof($level_struct)) {
		foreach($level_struct as $key => $value) {
		
			$link  = $link_to."?"; //id=".$key.",0,0,1,0,0";
			$link .= ($level_struct[$key]["acat_alias"]) ? html_specialchars($level_struct[$key]["acat_alias"]) : "id=".$key.",0,0,1,0,0";
			$css_list .= "    <li";
			$css_list .= ($level == $key) ? " id=\"".$class."_active\"":" id=\"".$class."_inactive\"";
			$css_list .= '><a href="'.$link.'"';
			$css_list .= ' target="_top">'.html_specialchars($level_struct[$key]["acat_name"])."</a>";
			$css_list .= "</li>\n";

		}
	}
	if($css_list) {
		$css_list = "<div id=\"".$class."\">\n  <ul id=\"".$class."_ul\">\n". $css_list ."  </ul>\n</div>";
	}
	return $css_list;
}

content.func.inc.php

Code: Select all


// -------------------------------------------------------------

// List based navigation of Single given Level - default listing Level 0
if( ! ( strpos($content["all"],'{NAV_LIST_LEVEL')===false ) ) {
	$content["all"] = str_replace('{NAV_LIST_LEVEL}', css_list_level($content["struct"],$content["cat_path"],$content["cat_id"]), $content["all"]);
	// creates a list styled nav menu of current level {NAV_LIST_LEVEL:active_level:class_name} | default class name = list_top
	$content["all"] = preg_replace('/\{NAV_LIST_LEVEL:(.*?):(.*?)\}/e', 'css_list_level($content["struct"],$content["cat_path"],$content["cat_id"],"$1","$2")', $content["all"]);
}

// -------------------------------------------------------------



So maybe there have been already some sophisticated solutions to this task but I simply didn´t find them, just show them please.


Cheers & Thank you

Uli
oleane
Posts: 17
Joined: Mon 26. Apr 2004, 22:07

Post by oleane »

Can you please tell us how the parent_level work ?
Is it a number ?
Can you give an exampel ?

Great a lot
:wink:
super ü
Posts: 6
Joined: Wed 28. Apr 2004, 12:47

Post by super ü »

Of course I can, it just takes a while, sorry.

So the parent_level is no real "level" it´s the id of the element which contains the sublevels you want to display as a menu.


So for example, if you have following site structure

-- Home
---- Home Sub 1
---- Home Sub 2
------ Home Sub 2 Sub 1
------ Home Sub 2 Sub 2
---- Home Sub 3

And Home is attached to ID 1,
so for the Tag

{NAV_LIST_LEVEL:1:}

you get this navigatable list with standart class:
  • Home Sub 1
    Home Sub 2
    Home Sub 3

If now e.g. you are on the "Home Sub 1" site, this element has the id class_active, if not class_inactive.

I hope this helped understanding.


But is there a documentation about available Variables while processing Replacement Tags? I´m still trying to get the active status independet from just the current level, so the active status in the example would reside at "Home Sub 2" if "Home Sub 2 Sub 1" is selected ....

Thanks for help
and Greetings!
dennart
Posts: 15
Joined: Tue 13. Apr 2004, 15:16

No correctly work

Post by dennart »

:) Sorry! But this tag not correctly work!!!

If I write {NA_LIST_LEVEL:1} in the page appear only

Menu1
Menu2
Menu3

But I want have
Menu1
-- submenu11
-- submenu21

Menu2
-- submenu21
-- submenu22

and etc.

May bee better rewrite this hack for next view

-- submenu11{nolink if current}
-- submenu21{link}


Dennis
Kaliningrad
super ü
Posts: 6
Joined: Wed 28. Apr 2004, 12:47

Post by super ü »

Sorry, but this is exactly the way this Tag should work.
The purpose is not to output a complete navigation for the whole page but to output a specific area of the site structure.

with this you are able to do flexible navigation systems. I needed this flexibility for a project and decided to share it, bu maybe it´s to specific.

Anyway there is a little update:

change in file: front.func.inc.php
(see instructions in starting post for details)

Code: Select all

// -------------------------------------------------------------

//recursive search if $end_level is a selected level
//returns true or false
function get_selected_status($struct,$start_level,$end_level,$array_store=false){
	if($array_store==false)$array_store = "";
	$array_store .= $start_level.",";
	$current_top = $struct[$start_level]["acat_struct"];			
	if($current_top != 0)
	{		
		return get_selected_status($struct,$current_top,$end_level,$array_store);
	}
	else
	{
		$array_store = explode(",",$array_store);
		return in_array($end_level,$array_store);
	}
}



function css_list_level($struct, $struct_path, $level, $parent_level="current", $class="list_level") {
	// returns list <div><ul><li></li></ul></div> of the structure level down from given parent_level
	// predefined class for this menu is "list_level"	
	
	if(!trim($class)) $class = "list_level";
	$parent_level_name = trim($parent_level_name);
	$level = intval($level);
	if($parent_level == "current") $parent_level = $level;
	$parent_level = intval($parent_level);
	
	
	$activated = 0; //no active list set
	$css_list = "";
	//returns the complete level of NON hidden categories
	$level_struct = return_struct_level($struct, $parent_level); 
	$sub_levels = count($level_struct);

	if(sizeof($level_struct)) {	
		foreach($level_struct as $key => $value) {
			$link  = $link_to."?"; //id=".$key.",0,0,1,0,0";
			$link .= ($level_struct[$key]["acat_alias"]) ? html_specialchars($level_struct[$key]["acat_alias"]) : "id=".$key.",0,0,1,0,0";
			$css_list .= "    <li";
			$css_list .= (get_selected_status($struct,$level,$key)) ? " id=\"".$class."_active\"":" id=\"".$class."_inactive\"";
			$css_list .= '><a href="'.$link.'"';
			$css_list .= ' target="_top">'.html_specialchars($level_struct[$key]["acat_name"])."</a>";
			$css_list .= "</li>\n";

		}
	}
	if($css_list) {
		$css_list = "<div id=\"".$class."\">\n  <ul id=\"".$class."_ul\">\n". $css_list ."  </ul>\n</div>";
	}
	
	return $css_list;
}

// -------------------------------------------------------------

Now a recursive Serach looks if a Menu Point ist somehow selected,
and attches the css id #(style_name)_active to those elements.


Hope it´s usefull for you to.
cheers


uli
----------------
mfg
Post Reply