Location: PHPKode > projects > WB News > includes/page-menu.php
<?php

/*========================================================*\
||########################################################||
||#                                                      #||
||#     WB News v2.0.0                                   #||
||# ---------------------------------------------------- #||
||#     Copyright (c) 2004-2007                          #||
||#     Created: 9th Feb 2007                            #||
||#     Filename: bitperms.php                           #||
||#                                                      #||
||########################################################||
/*========================================================*/

/**
 *  @author $Author: pmcilwaine $
 *	@version $Id: page-menu.php,v 1.1.2.2 2008/06/21 02:19:57 pmcilwaine Exp $
 */

$entry = isset( $params["entry"] ) ? $params["entry"] : "%s<br/>\n" ;
$separator = array_key_exists( "separator", $params ) ? $params["separator"] : "|" ;
$links = is_array( $params["links"] ) ? $params["links"] : FALSE ;
$class_open = isset( $params["class_open"] ) ? $params["class_open"] : FALSE ;
$enable_id = isset( $params["enable_id"] ) ? $params["enable_id"] : FALSE ;

$allow_icons = isset($params["allow_icons"]) ? $params["allow_icons"] : FALSE;
$replace_parent = isset($params["replace_parent"]) ? $params["replace_parent"] : FALSE;

if ( !$links )
{
	return FALSE;
}

$content = array();
foreach ( $links as $link )
{

	if ( isset($link["auth"]) && "" != $link["auth"] )
	{
		if ( !$auth->has_perm( $link["auth"] ) )
		{
			continue;
		}
	}

	$label = $link["label"];
	$query = isset( $link["query"] ) ? $link["query"] : array();

	$accesskey = NULL;
	preg_match ( "/(&)(\\S)/", $label, $match, PREG_OFFSET_CAPTURE );

	if ( $match )
	{
		$accesskey = strtolower( $match[2][0] );
		$tmpLabel = substr( $label, 0, $match[1][1] );
		$tmpLabel .= "<span style=\"text-decoration: underline;\">" . $match[2][0] . "</span>";
		$tmpLabel .= substr( $label, $match[2][1] + 1 );
		$label = $tmpLabel;
	}
	
	$tmp = "";

	if ( isset($link["return_page"]) && $link["return_page"] == TRUE && isset($_SESSION["return_page"]) )
	{
		$link["url"] = $_SESSION["return_page"];
	}
	else if ( isset($link["return_page"]) && $link["return_page"] == TRUE )
	{
		continue;
	}
	
	if ( isset($link["url"]) )
	{
		$url = $link["url"];
		if ( isset($link["add-key"]) )
		{
			$query["key"] = $key;
		}

		if ( is_array($query) && $query )
		{
			$url = make_url_html( $query, $url );
		}

		$tmp .= "<a href=\"$url\"";

		if ( $accesskey )
		{
			$tmp .= " accesskey=\"$accesskey\"";
		}

		if ( $class_open )
		{
			$node = substr( basename($url), 0, -4 );
			$current = substr( basename($_SERVER["PHP_SELF"]), 0, -4 );
			
			$OK = FALSE;
			foreach ( split("-", $current) as $name )
			{
				if ( $node == $name )
				{
					$OK = TRUE;
				}
			}

			if ( $OK )
			{
				$tmp .= " class=\"$class_open\"";
			}
		}

		if ( isset($link["attrs"]) && is_array($link["attrs"]) && count($link["attrs"]) > 0 )
		{
			$valid_attrs = array(
				"onclick",
				"class"
				);
			foreach ( $link["attrs"] as $attr => $value )
			{
				if ( in_array( $attr, $valid_attrs ) )
				{
					$tmp .= " " . htmlspecialchars($attr) . "=\"" . htmlspecialchars($value) . "\"";
				}
			}
		}
		
		$tmp .= ">";

		if ( isset($link["icon"]) && "" != $link["icon"] && $allow_icons )
		{
			$img = $link["icon"];
			$alt = str_replace("&", "", $link["label"] );
			$tmp .= "<img src=\"$img\" alt=\"$alt\" title=\"$alt\"/> ";
		}
		
		$tmp .= "$label</a>";
	}
	else
	{
		if ( isset($link["icon"]) )
		{
			$img = $link["icon"];
			$alt = str_replace("&", "", $link["label"] );
			$tmp .= "<img src=\"$img\" alt=\"$alt\" title=\"$alt\"/> ";
		}
		$tmp .= "$label";
	}

	if ( isset($link["desc"]) && "" != $link["desc"] )
	{
		$desc = $link["desc"];
		$tmp .= "<br/>$desc";
	}
	
	$cur_entry = $entry;
	if ( $replace_parent )
	{
		$cur_entry = str_replace( "{parent}", $link["parent"], $entry );
	}
	
	if ( $enable_id )
	{
		$content[] = sprintf( $cur_entry, str_replace("&", "", $link["label"] ), $tmp );
	}
	else
	{
		$content[] = sprintf( $cur_entry, $tmp );
	}
}

return sprintf( "<ul>\n%s</ul>", join( $separator, $content ) );

?>
Return current item: WB News