Versuche es mal mit dem rt NAV_SETLEVEL.
Dieser Replacement Tag rendert das Menü nur, wenn es auch etwas zu rendern gibt... allerdings als table.
Ich habe ihn noch um die Funktion {NAV_UL_SETLEVEL:(.*?):(.*?)\} erweitert – doch aufgrund miener nicht vorhandenen php-Kenntnissen solltest Du das vielleicht nicht einfach kopieren, sondern noch einmal genauer drüberschauen...
Code: Select all
<?php
/**
Version: 0.4 ( 0.3b rc <= 0.2b np <= 0.1b np <= 0.1a np)
never mind my bad lingo! =(
for further questions:
- read the readme.txt
- or visit http://www.phpwcms.de/forum/viewtopic.php?t=8411
- or e-mail to theravenevermore@web.de (betreff/subject: "reptag SETLEVEL")
**/
// -------------------------------------------------------------
// -------------------------------------------------------------
function get_active_categories_X($struct, $act_struct_id) {
// returns an array with all active categories/structure levels
$cat_incr = 1; // numbers the results consecutively - i think that's a great convenience. =D
$which_cat_array = array();
$which_category = $act_struct_id;
while($which_category) {
$which_cat_array[$which_category] = $cat_incr;
$which_category = $GLOBALS['content']["struct"][$which_category]["acat_struct"];
$cat_incr++; // remember: (x = x + 1 => x++)
}
return $which_cat_array;
}
// -------------------------------------------------------------
// ---- remember: --------------------------------------
// $content["struct"] = get_struct_data ($db, '', ''); //reads the complete structure as array
// $content["cat_id"] = $aktion[0];
// $content["cat_path"] = get_active_categories_X($content["struct"], $content["cat_id"]);
// -------------------------------------------------------------
// -------------------------------------------------------------
// remember: struct = $content["struct"] // catID = $content["cat_id"] // struct_path = $content["cat_path"]
function css_list_setlevel($struct, $catID, $struct_path, $parent_level_name="", $parent_level=0, $param_list_level_value="", $list_autohide="", $show_bg="", $class="", $link_to="index.php") {
// returns list <div><ul><li></li></ul></div> of the current structure level
// if $parent_level=1 the first list entry will be the parent level
// $parent_level=0 - only the list of all levels in this structure
// if $parent_leve_name != "" then it uses the given string
// predefined class for this menu is "list_level"
$class = trim($class);
if (!$class) {$class = "levelsensitive";}
$parent_level_name = trim($parent_level_name);
$parent_level = intval($parent_level);
$list_autohide = intval($list_autohide);
$show_bg = intval($show_bg);
$activated = 0; //no active list set
$css_list = "";
$param_list_level_value = intval($param_list_level_value);
// ---- levelsensitive ------------------------------------------
$array_order = array_flip(array_reverse(array_flip(get_active_categories_X($struct, $catID)))); // clean the mess up!
$shown_level_value = $param_list_level_value; // set value
$shown_level_key = array_search($shown_level_value,$array_order); // look up the key (shown_level_key) correlating with the value (shown_level_value)
if($list_autohide == 0){$hide_list = 0;} // check depth
if($list_autohide == 1 && !($shown_level_key > $param_tab_level_value)){$hide_list = 1; }
$level = $shown_level_key;
// -------------------------------------------------------------
// returns the complete level of NON hidden categories
$level_struct = return_struct_level($struct, $level);
// get the active link
$breadcrumb = get_breadcrumb(key($struct_path), $struct);
if($hide_list !== 1) {
foreach($level_struct as $key => $value) {
if(!$level_struct[$key]["acat_redirect"]) {
$link = 'index.php?';
if($level_struct[$key]["acat_alias"]) {
$link .= html_specialchars($level_struct[$key]["acat_alias"]);
} else {
$link .= 'id='.$key.',0,0,1,0,0';
}
$redirect['target'] = '';
} else {
$redirect = get_redirect_link($level_struct[$key]["acat_redirect"], ' ', '');
$link = $redirect['link'];
}
if(!empty($breadcrumb[$key])) {
$css_list .= '';
$css_list .= ' <li id="'.$class.'_active"><a href="'.$link.'" id="'.$class.'_active_link"'.$redirect['target'].'>';
$css_list .= html_specialchars($level_struct[$key]["acat_name"])."</a>";
$css_list .= "</li>\n";
// echo "wohoo ";
} else {
// echo "n�� ";
$css_list .= ' <li><a href="'.$link.'"'.$redirect['target'].'>';
$css_list .= html_specialchars($level_struct[$key]["acat_name"])."</a>";
$css_list .= "</li>\n"; }
}
} else if ($show_bg == 1){
$css_list = '<li> </li>';
}
if($parent_level && $level) {
$css_list_home = ' <li id="'.$class.'_parent">';
$css_list_home .= '<a href="'.$link_to.'?id='.$level; //former: id="'.$class.'_parent_link">';
$css_list_home .= ',0,0,1,0,0" id="'.$class.'_parent_link">';
$css_list_home .= html_specialchars((!$parent_level_name) ? $struct[$level]["acat_name"] : $parent_level_name);
$css_list_home .= "</a></li>\n";
$css_list = $css_list_home . $css_list;
}
if($css_list) {
$css_list = "<div id=\"".$class."\">\n <ul id=\"".$class."_ul\">\n". $css_list ." </ul>\n</div>";
}
return $css_list;
}
// -------------------------------------------------------------
// -------------------------------------------------------------
// ----- nav_table_struct
function set_level_tab($struct, $act_cat_id, $nav_table_struct, $param_tab_level_value="", $tab_autohide="", $link_to="index.php") {
// start with home directory for the listing = top nav structure
// 1. Build the recursive tree for given actual article category ID
// return the tree starting with given start_id (like breadcrumb)
// if the $start_id = 0 then this stops because 0 = top level
$data = array();
$c = 0;
$total_levels = 0;
$param_tab_level_value = intval($param_tab_level_value);
$tab_autohide = intval($tab_autohide);
$catID = $act_cat_id;
$start_id = $act_cat_id;
// ---- levelsensitive -----------------------------------------
$array_order = array_flip(array_reverse(array_flip(get_active_categories_X($struct, $catID))));
$shown_level_value = $param_tab_level_value;
$shown_level_key = array_search($shown_level_value,$array_order);
if($tab_autohide == 1 && !($shown_level_key > $param_tab_level_value)){$hide_tab = 1; }
if($tab_autohide == 0){$start_level = $param_tab_level_value;}
$level = $shown_level_key;
// -------------------------------------------------------------
// ---- if: determines, wether to show nav, or not
if( $hide_tab !== 1) {
while ($start_id) {
$data[$start_id] = 1;
$start_id = $struct[$start_id]["acat_struct"];
$total_levels++;
}
if(is_array($data) && count($data)) {
$temp_tree = array_reverse($data, 1);
} else {
$temp_tree = false;
}
foreach($struct as $key => $value) {
//2005-03-28 Oliver Georgi
//if($struct[$key]["acat_struct"] == $act_cat_id && $key && !$struct[$key]["acat_hidden"]) {
//show also when hidden level is on selected tree
if($struct[$key]["acat_struct"] == $act_cat_id && $key && (!$struct[$key]["acat_hidden"] || isset($GLOBALS['LEVEL_KEY'][$key]))) {
$c++;
}
}
$c = (!$c) ? 1 : 0;
//get depth of level
$level_depth = 0;
$start_level = $level;
while ($start_level) {
$start_level = $struct[$start_level]["acat_struct"];
$level_depth++;
}
//build image src path and real image tag
//$nav_table_struct["linkimage_norm_js"] = get_real_imgsrc($nav_table_struct["linkimage_norm"]);
$nav_table_struct["linkimage_over_js"] = get_real_imgsrc($nav_table_struct["linkimage_over"]);
//$nav_table_struct["linkimage_active_js"] = get_real_imgsrc($nav_table_struct["linkimage_active"]);
$nav_table_struct["linkimage_norm"] = add_linkid($nav_table_struct["linkimage_norm"], '#');
$nav_table_struct["linkimage_over"] = add_linkid($nav_table_struct["linkimage_over"], '#');
$nav_table_struct["linkimage_active"] = add_linkid($nav_table_struct["linkimage_active"], '#');
// create neccessary linkimage_array
//if(!isset($nav_table_struct['array_struct'])) {
// $nav_table_struct['array_struct'] = array();
//}
$lc = count($temp_tree);
for($l = 0; $l <= $lc; $l++) {
if(!isset($nav_table_struct['array_struct'][$l])) {
$nav_table_struct['array_struct'][$l]["linkimage_over_js"] = $nav_table_struct["linkimage_over_js"];
$nav_table_struct['array_struct'][$l]["linkimage_norm"] = $nav_table_struct["linkimage_norm"];
$nav_table_struct['array_struct'][$l]["linkimage_over"] = $nav_table_struct["linkimage_over"];
$nav_table_struct['array_struct'][$l]["linkimage_active"] = $nav_table_struct["linkimage_active"];
$nav_table_struct['array_struct'][$l]["row_norm_bgcolor"] = $nav_table_struct["row_norm_bgcolor"];
$nav_table_struct['array_struct'][$l]["row_norm_class"] = $nav_table_struct["row_norm_class"];
$nav_table_struct['array_struct'][$l]["row_over_bgcolor"] = $nav_table_struct["row_over_bgcolor"];
$nav_table_struct['array_struct'][$l]["row_active_bgcolor"] = $nav_table_struct["row_active_bgcolor"];
$nav_table_struct['array_struct'][$l]["row_active_class"] = $nav_table_struct["row_active_class"];
$nav_table_struct['array_struct'][$l]["space_celltop"] = $nav_table_struct["space_celltop"];
$nav_table_struct['array_struct'][$l]["space_cellbottom"] = $nav_table_struct["space_cellbottom"];
$nav_table_struct['array_struct'][$l]["cell_height"] = $nav_table_struct["cell_height"];
$nav_table_struct['array_struct'][$l]["cell_class"] = $nav_table_struct["cell_class"];
$nav_table_struct['array_struct'][$l]["cell_active_height"] = $nav_table_struct["cell_active_height"];
$nav_table_struct['array_struct'][$l]["cell_active_class"] = $nav_table_struct["cell_active_class"];
} else {
$nav_table_struct['array_struct'][$l]["linkimage_over_js"] = get_real_imgsrc($nav_table_struct['array_struct'][$l]["linkimage_over"]);
$nav_table_struct['array_struct'][$l]["linkimage_norm"] = add_linkid($nav_table_struct['array_struct'][$l]["linkimage_norm"], '#');
$nav_table_struct['array_struct'][$l]["linkimage_over"] = add_linkid($nav_table_struct['array_struct'][$l]["linkimage_over"], '#');
$nav_table_struct['array_struct'][$l]["linkimage_active"] = add_linkid($nav_table_struct['array_struct'][$l]["linkimage_active"], '#');
}
}
$temp_menu = build_levels ($struct, $level, $temp_tree, $act_cat_id, $nav_table_struct, $level_depth, $c, $link_to); //now: starts at $param_tab_level_value - former: starts at root level ($level)
return ($temp_menu) ? ("<table".table_attributes($nav_table_struct, "table", 0).">\n".$temp_menu."</table>") : "";
} /** TODO else {
echo $template_default["nav_table_struct"]["row_norm_bgcolor"];
$temp_menu = '<tr> <td style="background-color: #f0f0f0; width: 100%;"> </td> </tr>';
return ($temp_menu) ? ("<table>\n".$temp_menu."</table>") : "";
} **/
}
// -------------------------------------------------------------
// -------------------------------------------------------------
// ----- nav_ul_struct
function set_level_ul($struct, $act_cat_id, $nav_table_struct, $param_tab_level_value="", $tab_autohide="", $link_to="index.php") {
// start with home directory for the listing = top nav structure
// 1. Build the recursive tree for given actual article category ID
// return the tree starting with given start_id (like breadcrumb)
// if the $start_id = 0 then this stops because 0 = top level
$data = array();
$c = 0;
$total_levels = 0;
$param_tab_level_value = intval($param_tab_level_value);
$tab_autohide = intval($tab_autohide);
$catID = $act_cat_id;
$start_id = $act_cat_id;
// ---- levelsensitive -----------------------------------------
$array_order = array_flip(array_reverse(array_flip(get_active_categories_X($struct, $catID))));
$shown_level_value = $param_tab_level_value;
$shown_level_key = array_search($shown_level_value,$array_order);
if($tab_autohide == 1 && !($shown_level_key > $param_tab_level_value)){$hide_tab = 1; }
if($tab_autohide == 0){$start_level = $param_tab_level_value;}
$level = $shown_level_key;
// -------------------------------------------------------------
// ---- if: determines, wether to show nav, or not
if( $hide_tab !== 1) {
while ($start_id) {
$data[$start_id] = 1;
$start_id = $struct[$start_id]["acat_struct"];
$total_levels++;
}
if(is_array($data) && count($data)) {
$temp_tree = array_reverse($data, 1);
} else {
$temp_tree = false;
}
foreach($struct as $key => $value) {
//2005-03-28 Oliver Georgi
//if($struct[$key]["acat_struct"] == $act_cat_id && $key && !$struct[$key]["acat_hidden"]) {
//show also when hidden level is on selected tree
if($struct[$key]["acat_struct"] == $act_cat_id && $key && (!$struct[$key]["acat_hidden"] || isset($GLOBALS['LEVEL_KEY'][$key]))) {
$c++;
}
}
$c = (!$c) ? 1 : 0;
//get depth of level
$level_depth = 0;
$start_level = $level;
while ($start_level) {
$start_level = $struct[$start_level]["acat_struct"];
$level_depth++;
}
//build image src path and real image tag
//$nav_table_struct["linkimage_norm_js"] = get_real_imgsrc($nav_table_struct["linkimage_norm"]);
$nav_table_struct["linkimage_over_js"] = get_real_imgsrc($nav_table_struct["linkimage_over"]);
//$nav_table_struct["linkimage_active_js"] = get_real_imgsrc($nav_table_struct["linkimage_active"]);
$nav_table_struct["linkimage_norm"] = add_linkid($nav_table_struct["linkimage_norm"], '#');
$nav_table_struct["linkimage_over"] = add_linkid($nav_table_struct["linkimage_over"], '#');
$nav_table_struct["linkimage_active"] = add_linkid($nav_table_struct["linkimage_active"], '#');
// create neccessary linkimage_array
//if(!isset($nav_table_struct['array_struct'])) {
// $nav_table_struct['array_struct'] = array();
//}
$lc = count($temp_tree);
$temp_menu = build_levels_ul ($struct, $level, $temp_tree, $act_cat_id, $nav_table_struct, $level_depth, $c, $link_to); //now: starts at $param_tab_level_value - former: starts at root level ($level)
return ($temp_menu) ? ("<ul id=\"subnav\">\n".$temp_menu."</ul>") : "";
}
}
// -------------------------------------------------------------
function build_levels_ul ($struct, $level, $temp_tree, $act_cat_id, $nav_table_struct, $count, $div, $link_to) {
// this returns the level structure based on given arrays
// it is special for browsing from root levels
$temp_menu = '';
$js = '';
$depth = count($temp_tree)-$div;
$current_level = $count;
$count++;
$depth2 = $depth-$count+2;
foreach($struct as $key => $value) {
if( _getStructureLevelDisplayStatus($key, $level) ) {
/*
if( $struct[$key]["acat_struct"] == $level
&& $key
//&& (!$struct[$key]["acat_hidden"] || (!empty($nav_table_struct["show_active_hidden"]) && isset($GLOBALS['LEVEL_KEY'][$key])) ? true : false)
&& (!$struct[$key]['acat_hidden'] || ($struct[$key]["acat_hidden"] == 2 && isset($GLOBALS['LEVEL_KEY'][$key])))) {
*/
if(!$struct[$key]["acat_redirect"]) {
$link = 'index.php?';
if($struct[$key]["acat_alias"]) {
$link .= html_specialchars($struct[$key]["acat_alias"]);
} else {
$link .= 'id='.$key.',0,0,1,0,0';
}
$redirect['target'] = '';
} else {
$redirect = get_redirect_link($struct[$key]["acat_redirect"], ' ', '');
$link = $redirect['link'];
}
if(!empty($temp_tree[$key])) {
//check if inside active tree structure
if($act_cat_id == $key || (!empty($nav_table_struct["all_nodes_active"]) && isset($GLOBALS['LEVEL_KEY'][$key]))) {
$temp_menu .= '<li class="li_active">';
$temp_menu .= '<a href="'.$link.'"'.$redirect['target'].'>';
$temp_menu .= html_specialchars($struct[$key]["acat_name"]);
$temp_menu .= '</a>';
} else {
$temp_menu .= '<li class="li_inactive">';
$temp_menu .= '<a href="'.$link.'"'.$redirect['target'].'>';
$temp_menu .= html_specialchars($struct[$key]["acat_name"]);
$temp_menu .= '</a>';
}
// leeren level wieder loeschen...
$temp1_menu = "\n<ul>";
$temp2_menu = "";
$temp2_menu = build_levels_ul ($struct, $key, $temp_tree, $act_cat_id, $nav_table_struct, $count, $div, $link_to);
if ($temp2_menu !="") {
$temp1_menu .= $temp2_menu ."</ul></li>";
}
else {
$temp1_menu = "</li>";
}
$temp_menu .= $temp1_menu;
} else {
$temp_menu .= '<li class="li_inactive">';
$temp_menu .= '<a href="'.$link.'"'.$redirect['target'].'>';
$temp_menu .= html_specialchars($struct[$key]["acat_name"]);
$temp_menu .= '</a>';
$temp_menu .= "</li>";
}
}
}
return $temp_menu;
}
// -------------------------------------------------------------
// ---- NAV_LIST_SETLEVEL
$content["all"] = str_replace('{NAV_LIST_SETLEVEL}', '{NAV_LIST_SETLEVEL:0:0:0:1:0:levelsensitive}', $content["all"]);
if( ! ( strpos($content["all"],'{NAV_LIST_SETLEVEL')===false ) ) {
$replace = 'css_list_setlevel($content["struct"],$content["cat_id"],$content["cat_path"],"$1","$2","$3","$4","$5","$6")';
$content["all"] = preg_replace('/\{NAV_LIST_SETLEVEL:(.*?):(.*?):(.*?):(.*?):(.*?):(.*?)\}/e', $replace, $content["all"]);
}
// -------------------------------------------------------------
// -------------------------------------------------------------
// ---- NAV_TABLE_SETLEVEL
$content["all"] = str_replace('{NAV_TABLE_SETLEVEL}', '{NAV_TABLE_SETLEVEL:0:1}', $content["all"]);
if( ! ( strpos($content["all"],'{NAV_TABLE_SETLEVEL')===false ) ) {
$replace = 'set_level_tab($content["struct"],intval($content["cat_id"]),$template_default["nav_table_struct"],"$1","$2");';
$content["all"] = preg_replace('/\{NAV_TABLE_SETLEVEL:(.*?):(.*?)\}/e', $replace, $content["all"]);
}
// -------------------------------------------------------------
// -------------------------------------------------------------
// -------------------------------------------------------------
// ---- NAV_UL_SETLEVEL
$content["all"] = str_replace('{NAV_UL_SETLEVEL}', '{NAV_TABLE_SETLEVEL:0:1}', $content["all"]);
if( ! ( strpos($content["all"],'{NAV_UL_SETLEVEL')===false ) ) {
$replace = 'set_level_ul($content["struct"],intval($content["cat_id"]),$template_default["nav_table_struct"],"$1","$2");';
$content["all"] = preg_replace('/\{NAV_UL_SETLEVEL:(.*?):(.*?)\}/e', $replace, $content["all"]);
}
// -------------------------------------------------------------
// -------------------------------------------------------------
// ---- FIN. have fun. usta. ----
?>